List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:com.sun.fortress.compiler.codegen.CodeGenMethodVisitor.java
License:Open Source License
public void disposeCompilerLocal(int localId) { if (localId >= localVariableCount) { throw new CompilerError( "Trying to dispose of local " + localId + " but current metadata is off\nlocalVariableCount = " + localVariableCount + "\nvarNames = " + varNames); }// ww w. ja v a 2s.co m String ty = varTypes.get(localId); if (ty != null) { Label finish = new Label(); visitLabel(finish); visitLocalVariable(varNames.get(localId), ty, null, varFirstUse.get(localId), finish, localId); } Debug.debug(Debug.Type.CODEGEN, 2, "LOCAL destroy ", localId, " ", varNames.get(localId)); if (localId == (localVariableCount - 1)) { varNames.remove(localId); varTypes.remove(localId); varFirstUse.remove(localId); localVariableCount--; } else { varNames.set(localId, null); varTypes.set(localId, null); varFirstUse.set(localId, null); } }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Implementing "static reflection" for the method getFooRaw so the * interpreter uses a switch instruction for ***GetRaw * based on the hash values of String names in this namespace. *///from w w w . j av a2 s.com private static void writeMethodGetRaw(ClassWriter cw, String className, String methodName, EnvironmentClass environmentClass, EnvSymbolNames symbolNames) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(Ljava/lang/String;)" + environmentClass.descriptor(), null, null); mv.visitCode(); Label beginFunction = new Label(); mv.visitLabel(beginFunction); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I"); mv.visitVarInsn(Opcodes.ISTORE, 2); Label beginLoop = new Label(); mv.visitLabel(beginLoop); Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); Collections.sort(sortedCodes); Label returnNull = new Label(); getRawHelper(mv, className, hashCodeRelation, environmentClass, sortedCodes, returnNull); mv.visitLabel(returnNull); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); Label endFunction = new Label(); mv.visitLabel(endFunction); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, beginFunction, endFunction, 0); mv.visitLocalVariable("queryString", "Ljava/lang/String;", null, beginFunction, endFunction, 1); mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 2); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(2, 3); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void getRawHelper(MethodVisitor mv, String className, Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, List<Integer> sortedCodes, Label returnNull) { int[] codes = new int[sortedCodes.size()]; Label[] labels = new Label[sortedCodes.size()]; for (int i = 0; i < codes.length; i++) { codes[i] = sortedCodes.get(i);/*from ww w . j a v a 2s. co m*/ Label label = new Label(); labels[i] = label; } mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitLookupSwitchInsn(returnNull, codes, labels); for (int i = 0; i < codes.length; i++) { mv.visitLabel(labels[i]); getRawBaseCase(mv, className, hashCodeRelation, environmentClass, codes[i], returnNull); } }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void getRawBaseCase(MethodVisitor mv, String className, Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, int code, Label returnNull) {/* w w w . j av a 2 s . c o m*/ PredicateSet<String> strings = hashCodeRelation.matchSecond(code); for (String testString : strings) { mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(testString); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z"); Label afterReturn = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, afterReturn); mv.visitVarInsn(Opcodes.ALOAD, 0); String idString = testString + environmentClass.namespace(); mv.visitFieldInsn(Opcodes.GETFIELD, className, Naming.mangleIdentifier(idString), environmentClass.descriptor()); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(afterReturn); } mv.visitJumpInsn(Opcodes.GOTO, returnNull); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Implementing "static reflection" for the method putRaw so the * interpreter uses a switch instruction for ***PutRaw * based on the hash values of String names in this namespace. *//*from w w w. j ava 2 s. c o m*/ private static void writeMethodPutRaw(ClassWriter cw, String className, String methodName, EnvironmentClass environmentClass, EnvSymbolNames symbolNames) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + STRING_DESCRIPTOR + environmentClass.descriptor() + ")V", null, null); mv.visitCode(); Label beginFunction = new Label(); mv.visitLabel(beginFunction); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STRING_INTERNALNAME, "hashCode", "()I"); mv.visitVarInsn(Opcodes.ISTORE, 3); Label beginLoop = new Label(); mv.visitLabel(beginLoop); Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); Collections.sort(sortedCodes); Label notFound = new Label(); putRawHelper(mv, className, environmentClass, hashCodeRelation, sortedCodes, notFound); mv.visitLabel(notFound); mv.visitInsn(Opcodes.RETURN); Label endFunction = new Label(); mv.visitLabel(endFunction); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, beginFunction, endFunction, 0); mv.visitLocalVariable("queryString", STRING_DESCRIPTOR, null, beginFunction, endFunction, 1); mv.visitLocalVariable("value", environmentClass.descriptor(), null, beginFunction, endFunction, 2); mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 3); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(2, 4); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void putRawHelper(MethodVisitor mv, String className, EnvironmentClass environmentClass, Relation<String, Integer> hashCodeRelation, List<Integer> sortedCodes, Label notFound) { int[] codes = new int[sortedCodes.size()]; Label[] labels = new Label[sortedCodes.size()]; for (int i = 0; i < codes.length; i++) { codes[i] = sortedCodes.get(i);//w ww . j a v a 2 s. com Label label = new Label(); labels[i] = label; } mv.visitVarInsn(Opcodes.ILOAD, 3); mv.visitLookupSwitchInsn(notFound, codes, labels); for (int i = 0; i < codes.length; i++) { mv.visitLabel(labels[i]); putRawBaseCase(mv, className, hashCodeRelation, environmentClass, codes[i], notFound); } }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void putRawBaseCase(MethodVisitor mv, String className, Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, int code, Label notFound) {/*ww w . ja v a 2s. c om*/ PredicateSet<String> strings = hashCodeRelation.matchSecond(code); for (String testString : strings) { mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(testString); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z"); Label afterSetValue = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, afterSetValue); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 2); String idString = testString + environmentClass.namespace(); mv.visitFieldInsn(Opcodes.PUTFIELD, className, Naming.mangleIdentifier(idString), environmentClass.descriptor()); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(afterSetValue); } mv.visitJumpInsn(Opcodes.GOTO, notFound); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeNullGetter(ClassWriter cw, String className, String methodName, String signature) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, signature, null, null); mv.visitCode();/*from w w w . j av a 2s . c om*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l1, 0); mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(1, 2); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeNullSetter(ClassWriter cw, String className, String methodName, String signature) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, signature, null, null); mv.visitCode();//from w ww . ja v a 2 s. c o m Label l0 = new Label(); mv.visitLabel(l0); mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l1, 0); mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); mv.visitLocalVariable("f2", "Ljava/lang/Number;", null, l0, l1, 2); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(0, 3); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeRemoveMethod(ClassWriter cw, String className, String methodName, String invokeMethod, EnvironmentClass environmentClass) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(Ljava/lang/String;)V", null, null); mv.visitCode();//from w w w . ja v a 2s .c o m Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, invokeMethod, "(Ljava/lang/String;" + environmentClass.descriptor() + ")V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(Opcodes.RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l2, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l2, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(3, 2); mv.visitEnd(); }