List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:org.evosuite.testcarver.instrument.TransformerUtil.java
License:Open Source License
public static boolean isStatic(final int access) { return (access & Opcodes.ACC_STATIC) != 0; }
From source file:org.fehrman.jcm.find.Find.java
License:CDDL license
@SuppressWarnings("unchecked") private String processMethod(MethodNode methodNode) throws Exception //---------------------------------------------------------------- { StringBuilder methodDescription = new StringBuilder(); String className = null;//from www . j a v a 2 s.c o m Type returnType = Type.getReturnType(methodNode.desc); Type[] argumentTypes = Type.getArgumentTypes(methodNode.desc); List<String> thrownInternalClassNames = methodNode.exceptions; _logger.entering(CLASS, Thread.currentThread().getStackTrace()[1].getMethodName()); if ((methodNode.access & Opcodes.ACC_PUBLIC) != 0) { methodDescription.append("public "); } if ((methodNode.access & Opcodes.ACC_PRIVATE) != 0) { methodDescription.append("private "); } if ((methodNode.access & Opcodes.ACC_PROTECTED) != 0) { methodDescription.append("protected "); } if ((methodNode.access & Opcodes.ACC_STATIC) != 0) { methodDescription.append("static "); } if ((methodNode.access & Opcodes.ACC_ABSTRACT) != 0) { methodDescription.append("abstract "); } if ((methodNode.access & Opcodes.ACC_SYNCHRONIZED) != 0) { methodDescription.append("synchronized "); } className = returnType.getClassName(); if (className != null && className.startsWith(JAVA_LANG)) { methodDescription.append(className.substring(JAVA_LANG.length())); } else { methodDescription.append(className); } methodDescription.append(" "); methodDescription.append(methodNode.name); methodDescription.append("("); for (int i = 0; i < argumentTypes.length; i++) { Type argumentType = argumentTypes[i]; if (i > 0) { methodDescription.append(", "); } className = argumentType.getClassName(); if (className != null && className.startsWith(JAVA_LANG)) { methodDescription.append(className.substring(JAVA_LANG.length())); } else { methodDescription.append(className); } } methodDescription.append(")"); if (!thrownInternalClassNames.isEmpty()) { methodDescription.append(" throws "); int i = 0; for (String thrownInternalClassName : thrownInternalClassNames) { if (i > 0) { methodDescription.append(", "); } className = Type.getObjectType(thrownInternalClassName).getClassName(); if (className != null && className.startsWith(JAVA_LANG)) { methodDescription.append(className.substring(JAVA_LANG.length())); } else { methodDescription.append(className); } i++; } } _logger.exiting(CLASS, Thread.currentThread().getStackTrace()[1].getMethodName()); return methodDescription.toString(); }
From source file:org.formulacompiler.compiler.internal.bytecode.ClassCompiler.java
License:Open Source License
private void buildStaticInitializer() { this.initializer = newMethod(Opcodes.ACC_STATIC, "<clinit>", "()V"); }
From source file:org.formulacompiler.compiler.internal.bytecode.TypeCompilerForBigDecimals.java
License:Open Source License
private final String defineOrReuseStaticConstant(String _value) { String result = this.constantPool.get(_value); if (result == null) { final ClassWriter cw = rootCompiler().cw(); final GeneratorAdapter ci = rootCompiler().initializer(); result = "C$" + Integer.toString(this.constantPool.size()); cw.visitField(Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, result, B, null, null).visitEnd(); final BigDecimal bigValue = new BigDecimal(_value); if (bigValue.precision() <= MAX_LONG_PREC) { final long longValue = bigValue.unscaledValue().longValue(); ci.push(longValue);//from ww w . j a v a 2s . c o m ci.push(bigValue.scale()); ci.visitMethodInsn(Opcodes.INVOKESTATIC, BNAME, "valueOf", LI2B); if (needsAdjustment(bigValue)) { compileAdjustment(ci); } } else { ci.push(_value); compileRuntimeMethod(ci, "newBigDecimal", S2B); compileAdjustment(ci); } ci.visitFieldInsn(Opcodes.PUTSTATIC, rootCompiler().classInternalName(), result, B); this.constantPool.put(_value, result); } return result; }
From source file:org.formulacompiler.compiler.internal.bytecode.TypeCompilerForPrecisionBigDecimals.java
License:Open Source License
final void buildStaticContext() { if (this.staticContextBuilt) return;/* www .j ava2 s . co m*/ this.staticContextBuilt = true; final SectionCompiler root = engineCompiler().rootCompiler(); final ClassWriter cw = root.cw(); final FieldVisitor fv = cw.visitField(Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, RUNTIME_CONTEXT_NAME, RUNTIME_CONTEXT_TYPE.getDescriptor(), null, null); fv.visitEnd(); final GeneratorAdapter mv = root.initializer(); final MathContext mc = numericType().mathContext(); if (mc == MathContext.DECIMAL32) { compilePredefinedMathContext(mv, "DECIMAL32"); } else if (mc == MathContext.DECIMAL64) { compilePredefinedMathContext(mv, "DECIMAL64"); } else if (mc == MathContext.DECIMAL128) { compilePredefinedMathContext(mv, "DECIMAL128"); } else if (mc == MathContext.UNLIMITED) { compilePredefinedMathContext(mv, "UNLIMITED"); } else { mv.visitTypeInsn(Opcodes.NEW, RUNTIME_CONTEXT_TYPE.getInternalName()); mv.visitInsn(Opcodes.DUP); mv.push(mc.getPrecision()); final Type modeType = Type.getType(RoundingMode.class); mv.getStatic(modeType, mc.getRoundingMode().name(), modeType); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, RUNTIME_CONTEXT_TYPE.getInternalName(), "<init>", "(ILjava/math/RoundingMode;)V"); } mv.visitFieldInsn(Opcodes.PUTSTATIC, root.classInternalName(), RUNTIME_CONTEXT_NAME, RUNTIME_CONTEXT_DESCRIPTOR); }
From source file:org.formulacompiler.compiler.internal.bytecode.TypeCompilerForScaledLongs.java
License:Open Source License
final void buildStaticContext() { if (this.staticContextBuilt) return;// w ww.ja va2 s . c om this.staticContextBuilt = true; final SectionCompiler root = engineCompiler().rootCompiler(); final ClassWriter cw = root.cw(); final FieldVisitor fv = cw.visitField(Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, RUNTIME_CONTEXT_NAME, RUNTIME_CONTEXT_TYPE.getDescriptor(), null, null); fv.visitEnd(); final GeneratorAdapter mv = root.initializer(); mv.visitTypeInsn(Opcodes.NEW, RUNTIME_CONTEXT_TYPE.getInternalName()); mv.visitInsn(Opcodes.DUP); mv.push(numericType().scale()); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, RUNTIME_CONTEXT_TYPE.getInternalName(), "<init>", "(I)V"); mv.visitFieldInsn(Opcodes.PUTSTATIC, root.classInternalName(), RUNTIME_CONTEXT_NAME, RUNTIME_CONTEXT_DESCRIPTOR); }
From source file:org.freud.analysed.classbytecode.parser.asm.AsmField.java
License:Apache License
@Override public boolean isStatic() { return isAccessModifier(Opcodes.ACC_STATIC); }
From source file:org.glassfish.pfl.tf.spi.EnhancedClassDataASMImpl.java
License:Open Source License
private void scanMethods() { final List<MethodNode> methods = currentClass.methods; Map<String, String> mmnToDescriptions = new HashMap<String, String>(); Map<String, TimingPointType> mmnToTPT = new HashMap<String, TimingPointType>(); Map<String, String> mmnToTPN = new HashMap<String, String>(); Map<String, String> mmnToAnnotationName = new HashMap<String, String>(); for (MethodNode mn : methods) { final String mname = mn.name; final String mdesc = util.getFullMethodDescriptor(mn); String monitoredMethodMMAnno = null; String shortClassName = className; int index = shortClassName.lastIndexOf('/'); if (index >= 0) { shortClassName = className.substring(index + 1); }/*from w w w. j a v a 2 s . co m*/ String description = "Timer for method " + mname + " in class " + shortClassName; // default TimingPointType tpt = TimingPointType.BOTH; // default for non-InfoMethod String tpName = mname; // default for non-InfoMethod boolean hasMethodInfoAnno = false; final List<AnnotationNode> annotations = mn.visibleAnnotations; if (annotations != null) { for (AnnotationNode an : annotations) { final String aname = Type.getType(an.desc).getInternalName(); if (aname.equals(DESCRIPTION_NAME)) { Object value = getAttribute(an, "value"); if (value != null && value instanceof String) { description = (String) value; } } else if (aname.equals(INFO_METHOD_NAME)) { // set the correct default for InfoMethod! tpt = TimingPointType.NONE; // Check for private method! if (!util.hasAccess(mn.access, Opcodes.ACC_PRIVATE)) { util.error("Method " + mdesc + " for Class " + currentClass.name + " is a non-private @InfoMethod," + " which is not allowed"); } hasMethodInfoAnno = true; Object value = getAttribute(an, "tpType"); if (value != null && value instanceof String[]) { String[] enumData = (String[]) value; if (enumData.length == 2) { // [0] is desc, [1] is value tpt = TimingPointType.valueOf(enumData[1]); } } Object value2 = getAttribute(an, "tpName"); String tpn = ""; if ((value2 != null) && value2 instanceof String) { tpn = (String) value2; } if (tpt != TimingPointType.NONE) { if (tpn.length() == 0) { util.error("Method " + mdesc + " for Class " + currentClass.name + " is an info method with timing point type " + tpt + " but no tpName was specified"); } else { tpName = tpn; } } } else if (annoNamesForClass.contains(aname)) { if (monitoredMethodMMAnno == null) { monitoredMethodMMAnno = aname; } else { util.error("Method " + mdesc + " for Class " + currentClass.name + "has multiple MM annotations"); } } else if (annotationNames.contains(aname)) { util.error("Method " + mdesc + " for Class " + currentClass.name + " has an MM annotation which " + "is not on its class"); } } if (hasMethodInfoAnno && monitoredMethodMMAnno != null) { util.error("Method " + mdesc + " for Class " + currentClass.name + " has both @InfoMethod annotation and" + " a MM annotation"); } // This check is not really essential, but it simplifies // passing information to later phases for code generation // if we can assume that all @InfoMethod annotated methods // are non-static. (Simply because we only need to look for // INVOKESPECIAL). final boolean isStatic = util.hasAccess(mn.access, Opcodes.ACC_STATIC); if (hasMethodInfoAnno && isStatic) { util.error("Method " + mdesc + " for Class " + currentClass.name + " is a static method, but must not be"); } // TF Annotations are not permitted on constructors if (mname.equals("<init>")) { if (hasMethodInfoAnno) { util.error("Constructors must not have an " + "@InfoMethod annotations"); } else if (monitoredMethodMMAnno != null) { util.error("Constructors must not have an " + "MM annotation"); } } // This will be a null value for InfoMethods, which is what // we want. mmnToAnnotationName.put(mname, monitoredMethodMMAnno); // We could have a method at this point that is annotated with // something OTHER than tracing annotations. Do not add // such methods to the ECD. if (hasMethodInfoAnno || (monitoredMethodMMAnno != null)) { // Both infoMethods and MM annotated methods go into // methodNames methodNames.add(mname); mmnToDescriptions.put(mname, description); mmnToTPT.put(mname, tpt); mmnToTPN.put(mname, tpName); if (hasMethodInfoAnno) { infoMethodDescs.add(mdesc); } else { mmMethodDescs.add(mdesc); methodToAnno.put(mdesc, monitoredMethodMMAnno); } } } } Collections.sort(methodNames); for (String str : methodNames) { methodDescriptions.add(mmnToDescriptions.get(str)); methodTPTs.add(mmnToTPT.get(str)); methodAnnoList.add(mmnToAnnotationName.get(str)); methodTPNames.add(mmnToTPN.get(str)); } if (util.getDebug()) { util.msg("\tinfoMethodDescs = " + infoMethodDescs); util.msg("\tmmMethodDescs = " + mmMethodDescs); util.msg("\tmethodNames = " + methodNames); util.msg("\tmethodToAnno = " + methodToAnno); util.msg("\tmethodDescriptions = " + methodDescriptions); util.msg("\tmethodTPTs = " + methodTPTs); util.msg("\tmethodTPNs = " + methodTPNames); } }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void wrapArgs(MethodVisitor mv, int access, String desc) { info(2, "Wrapping args for descriptor " + desc); Type[] atypes = Type.getArgumentTypes(desc); emitIntConstant(mv, atypes.length);/*from w w w .j av a2s . c o m*/ mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); int argIndex; if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) { argIndex = 0; } else { argIndex = 1; } for (int ctr = 0; ctr < atypes.length; ctr++) { mv.visitInsn(Opcodes.DUP); emitIntConstant(mv, ctr); argIndex = wrapArg(mv, argIndex, atypes[ctr]); mv.visitInsn(Opcodes.AASTORE); } }
From source file:org.glassfish.pfl.tf.tools.enhancer.ClassEnhancer.java
License:Open Source License
@Override public void visitEnd() { info(2, "visitEnd"); // Add the additional fields final String desc = Type.getDescriptor(SynchronizedHolder.class); final int acc = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC; // Signature is actually L../SynchronizedHolder;<L.../MethodMonitor;> // where the ... are replaced with appropriate packages. Not // that we actually need a signature here. final String sig = null; for (String fname : ecd.getAnnotationToHolderName().values()) { info(2, "Adding field " + fname + " of type " + desc); cv.visitField(acc, fname, desc, sig, null); }/*from ww w. ja va 2 s . co m*/ if (!hasStaticInitializer) { info(2, "creating static init"); int siacc = Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE; MethodVisitor mv = cv.visitMethod(siacc, "<clinit>", "()V", null, null); if (util.getDebug()) { mv = new SimpleMethodTracer(mv, util); } MethodAdapter ma = new StaticInitVisitor(siacc, "()V", mv, util, ecd); ma.visitCode(); ma.visitInsn(Opcodes.RETURN); // Only if creating a <clinit>! ma.visitMaxs(0, 0); ma.visitEnd(); } super.visitEnd(); ecd.updateInfoDesc(); }