Java Code Examples for org.objectweb.asm.commons.GeneratorAdapter#ifNull()

The following examples show how to use org.objectweb.asm.commons.GeneratorAdapter#ifNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemInstrument.java    From dacapobench with Apache License 2.0 6 votes vote down vote up
public void visitEnd() {
	if (! doneAddField) {
		doneAddField = true;
		
		super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_FIELD, Type.getDescriptor(Agent.class), null, null);
	}
	
	if (! doneAddMethod) {
		doneAddMethod = true;

		GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(LOG_CLASS_METHOD, LOG_CLASS_SIGNATURE), LOG_CLASS_SIGNATURE, new Type[] {}, this);

		Label target = mg.newLabel();
		mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
		mg.ifNull(target);
		mg.push(LOG_INTERNAL_TYPE);
		mg.putStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
		mg.mark(target);
		mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
		mg.returnValue();
	}
	
	super.visitEnd();
}
 
Example 2
Source File: ExpressionIsNull.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	Label labelNull = new Label();
	Label labelExit = new Label();

	expression.load(ctx);
	g.ifNull(labelNull);
	g.push(false);
	g.goTo(labelExit);

	g.mark(labelNull);
	g.push(true);

	g.mark(labelExit);

	return Type.BOOLEAN_TYPE;
}
 
Example 3
Source File: ExpressionHash.java    From datakernel with Apache License 2.0 4 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	int resultVar = g.newLocal(INT_TYPE);

	boolean firstIteration = true;

	for (Expression argument : arguments) {
		if (firstIteration) {
			g.push(0);
			firstIteration = false;
		} else {
			g.push(31);
			g.loadLocal(resultVar);
			g.math(IMUL, INT_TYPE);
		}

		Type fieldType = argument.load(ctx);

		if (isPrimitiveType(fieldType)) {
			if (fieldType.getSort() == Type.LONG) {
				g.dup2();
				g.push(32);
				g.visitInsn(LUSHR);
				g.visitInsn(LXOR);
				g.visitInsn(L2I);
			}
			if (fieldType.getSort() == Type.FLOAT) {
				g.invokeStatic(getType(Float.class), getMethod("int floatToRawIntBits (float)"));
			}
			if (fieldType.getSort() == Type.DOUBLE) {
				g.invokeStatic(getType(Double.class), getMethod("long doubleToRawLongBits (double)"));
				g.dup2();
				g.push(32);
				g.visitInsn(LUSHR);
				g.visitInsn(LXOR);
				g.visitInsn(L2I);
			}
			g.visitInsn(IADD);
		} else {
			int tmpVar = g.newLocal(fieldType);
			g.storeLocal(tmpVar);
			g.loadLocal(tmpVar);
			Label ifNullLabel = g.newLabel();
			g.ifNull(ifNullLabel);
			g.loadLocal(tmpVar);
			g.invokeVirtual(fieldType, getMethod("int hashCode()"));
			g.visitInsn(IADD);
			g.mark(ifNullLabel);
		}

		g.storeLocal(resultVar);
	}

	if (firstIteration) {
		g.push(0);
	} else {
		g.loadLocal(resultVar);
	}

	return INT_TYPE;
}
 
Example 4
Source File: ExpressionComparator.java    From datakernel with Apache License 2.0 4 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	Label labelReturn = new Label();

	for (ComparablePair pair : pairs) {
		Type leftPropertyType = pair.left.load(ctx);
		Type rightPropertyType = pair.right.load(ctx);

		checkArgument(leftPropertyType.equals(rightPropertyType), "Types of compared values should match");
		if (isPrimitiveType(leftPropertyType)) {
			g.invokeStatic(wrap(leftPropertyType), new Method("compare", INT_TYPE, new Type[]{leftPropertyType, leftPropertyType}));
			g.dup();
			g.ifZCmp(NE, labelReturn);
			g.pop();
		} else if (!pair.nullable) {
			g.invokeVirtual(leftPropertyType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)}));
			g.dup();
			g.ifZCmp(NE, labelReturn);
			g.pop();
		} else {
			VarLocal varRight = ctx.newLocal(rightPropertyType);
			varRight.store(ctx);

			VarLocal varLeft = ctx.newLocal(leftPropertyType);
			varLeft.store(ctx);

			Label continueLabel = new Label();
			Label nonNulls = new Label();
			Label leftNonNull = new Label();

			varLeft.load(ctx);
			g.ifNonNull(leftNonNull);

			varRight.load(ctx);
			g.ifNull(continueLabel);
			g.push(-1);
			g.returnValue();

			g.mark(leftNonNull);

			varRight.load(ctx);
			g.ifNonNull(nonNulls);
			g.push(1);
			g.returnValue();

			g.mark(nonNulls);

			varLeft.load(ctx);
			varRight.load(ctx);

			g.invokeVirtual(leftPropertyType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)}));
			g.dup();
			g.ifZCmp(NE, labelReturn);
			g.pop();

			g.mark(continueLabel);
		}
	}

	g.push(0);

	g.mark(labelReturn);

	return INT_TYPE;
}
 
Example 5
Source File: ExpressionToString.java    From datakernel with Apache License 2.0 4 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	g.newInstance(getType(StringBuilder.class));
	g.dup();
	g.invokeConstructor(getType(StringBuilder.class), getMethod("void <init> ()"));

	boolean first = true;

	for (Object key : arguments.keySet()) {
		String str = first ? begin : separator;
		first = false;
		if (key instanceof String) {
			str += key;
		}
		if (!str.isEmpty()) {
			g.dup();
			g.push(str);
			g.invokeVirtual(getType(StringBuilder.class), getMethod("StringBuilder append(String)"));
			g.pop();
		}

		g.dup();
		Expression expression = arguments.get(key);
		Type type = expression.load(ctx);
		if (isPrimitiveType(type)) {
			g.invokeStatic(wrap(type), new Method("toString", getType(String.class), new Type[]{type}));
		} else {
			Label nullLabel = new Label();
			Label afterToString = new Label();
			g.dup();
			g.ifNull(nullLabel);
			g.invokeVirtual(type, getMethod("String toString()"));
			g.goTo(afterToString);
			g.mark(nullLabel);
			g.pop();
			g.push("null");
			g.mark(afterToString);
		}
		g.invokeVirtual(getType(StringBuilder.class), getMethod("StringBuilder append(String)"));
		g.pop();
	}

	if (!end.isEmpty()) {
		g.dup();
		g.push(end);
		g.invokeVirtual(getType(StringBuilder.class), getMethod("StringBuilder append(String)"));
		g.pop();
	}

	g.invokeVirtual(getType(StringBuilder.class), getMethod("String toString()"));
	return getType(String.class);
}