private void defineFields() { for (Map.Entry<String, Class> fieldSignature : getFieldSignatures().entrySet()) { String fieldName = fieldSignature.getKey(); Class type = fieldSignature.getValue(); Map<Class, Map<String, Object>> fieldAnnos = getFieldAnnotations().get(fieldName); FieldVisitor fieldVisitor = cw.visitField(ACC_PUBLIC, fieldName, ci(type), null, null); if (fieldAnnos == null) continue; for (Map.Entry<Class, Map<String, Object>> fieldAnno : fieldAnnos.entrySet()) { Class annoType = fieldAnno.getKey(); AnnotationVisitor av = fieldVisitor.visitAnnotation(ci(annoType), true); CodegenUtils.visitAnnotationFields(av, fieldAnno.getValue()); } fieldVisitor.visitEnd(); } }
public String getNewStaticConstant(String type, String name_prefix) { ClassVisitor cv = getClassVisitor(); String realName; synchronized (this) { realName = "__" + constants++; } // declare the field cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, realName, type, null, null).visitEnd(); return realName; } }
public String getNewStaticConstant(String type, String name_prefix) { ClassVisitor cv = getClassVisitor(); String realName; synchronized (this) { realName = "__" + constants++; } // declare the field cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, realName, type, null, null).visitEnd(); return realName; } }
private ClassWriter beginProxyClass(final String className, final Class superClass, final Class[] interfaces) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); // start class cw.visit(Opcodes.V1_3, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER, toInternalClassName(className), /*signature*/ null, toInternalClassName(superClass), interfaceNamesForProxyClass(interfaces)); cw.visitField(Opcodes.ACC_PRIVATE, INVOCATION_HANDLER_FIELD_NAME, INVOCATION_HANDLER_TYPE.getDescriptor(), null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, PROXY_CLASS_FIELD_NAME, PROXY_CLASS_TYPE.getDescriptor(), null, null).visitEnd(); return cw; }
private void defineFields() { for (Map.Entry<String, Class> fieldSignature : getFieldSignatures().entrySet()) { String fieldName = fieldSignature.getKey(); Class type = fieldSignature.getValue(); Map<Class, Map<String, Object>> fieldAnnos = getFieldAnnotations().get(fieldName); FieldVisitor fieldVisitor = cw.visitField(ACC_PUBLIC, fieldName, ci(type), null, null); if (fieldAnnos == null) continue; for (Map.Entry<Class, Map<String, Object>> fieldAnno : fieldAnnos.entrySet()) { Class annoType = fieldAnno.getKey(); AnnotationVisitor av = fieldVisitor.visitAnnotation(ci(annoType), true); CodegenUtils.visitAnnotationFields(av, fieldAnno.getValue()); } fieldVisitor.visitEnd(); } }
private ClassWriter beginProxyClass(final String className, final Class superClass, final Class[] interfaces) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); // start class cw.visit(Opcodes.V1_3, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER, toInternalClassName(className), /*signature*/ null, toInternalClassName(superClass), interfaceNamesForProxyClass(interfaces)); cw.visitField(Opcodes.ACC_PRIVATE, INVOCATION_HANDLER_FIELD_NAME, INVOCATION_HANDLER_TYPE.getDescriptor(), null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, PROXY_CLASS_FIELD_NAME, PROXY_CLASS_TYPE.getDescriptor(), null, null).visitEnd(); return cw; }
AnnotationVisitor av = fieldVisitor.visitAnnotation(ci(annoType), true); CodegenUtils.visitAnnotationFields(av, fieldAnno.getValue()); fieldVisitor.visitEnd();
public String getNewField(String type, String name, Object init) { ClassVisitor cv = getClassVisitor(); // declare the field cv.visitField(ACC_PRIVATE, name, type, null, null).visitEnd(); if(init != null) { initMethod.aload(THIS); initMethod.ldc(init); initMethod.putfield(getClassname(),name, type); } return name; }
AnnotationVisitor av = fieldVisitor.visitAnnotation(ci(annoType), true); CodegenUtils.visitAnnotationFields(av, fieldAnno.getValue()); fieldVisitor.visitEnd();
public String getNewField(String type, String name, Object init) { ClassVisitor cv = getClassVisitor(); // declare the field cv.visitField(ACC_PRIVATE, name, type, null, null).visitEnd(); if(init != null) { initMethod.aload(THIS); initMethod.ldc(init); initMethod.putfield(getClassname(),name, type); } return name; }
private static ClassWriter beginProxyClass(final String className, final Class superClass, final Class[] interfaces, final ClassDefiningClassLoader loader) { ClassWriter cw = ASM.newClassWriter(loader.asClassLoader()); // start class cw.visit(JAVA_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER, toInternalClassName(className), /*signature*/ null, toInternalClassName(superClass), interfaceNamesForProxyClass(interfaces)); // private final JavaProxyInvocationHandler __handler; cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, INVOCATION_HANDLER_FIELD_NAME, INVOCATION_HANDLER_TYPE.getDescriptor(), null, null ).visitEnd(); // /* public */ static final JavaProxyClass __proxy_class; cw.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, PROXY_CLASS_FIELD_NAME, PROXY_CLASS_TYPE.getDescriptor(), null, null ).visitEnd(); return cw; }
private static ClassWriter beginProxyClass(final String className, final Class superClass, final Class[] interfaces, final ClassDefiningClassLoader loader) { ClassWriter cw = ASM.newClassWriter(loader.asClassLoader()); // start class cw.visit(JAVA_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER, toInternalClassName(className), /*signature*/ null, toInternalClassName(superClass), interfaceNamesForProxyClass(interfaces)); // private final JavaProxyInvocationHandler __handler; cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, INVOCATION_HANDLER_FIELD_NAME, INVOCATION_HANDLER_TYPE.getDescriptor(), null, null ).visitEnd(); // /* public */ static final JavaProxyClass __proxy_class; cw.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, PROXY_CLASS_FIELD_NAME, PROXY_CLASS_TYPE.getDescriptor(), null, null ).visitEnd(); return cw; }
public String getNewConstant(String type, String name_prefix, Object init) { ClassVisitor cv = getClassVisitor(); String realName = getNewConstantName(); // declare the field cv.visitField(ACC_PRIVATE, realName, type, null, null).visitEnd(); if(init != null) { initMethod.aload(THIS); initMethod.ldc(init); initMethod.putfield(getClassname(),realName, type); } return realName; }
@Override public void Scope(Scope scope) { IRScope irScope = scope.getScope(); String name = JavaNameMangler.encodeScopeForBacktrace(irScope) + '$' + methodIndex++ + "_IRSCope"; if (scopeMap.get(name) == null) { scopeMap.put(name, irScope); jvm.cls().visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_VOLATILE, name, ci(IRScope.class), null, null).visitEnd(); } jvmAdapter().getstatic(jvm.clsData().clsName, name, ci(IRScope.class)); jvmAdapter().invokestatic(p(Helpers.class), "getStaticScope", sig(StaticScope.class, IRScope.class)); }
@Override public void Scope(Scope scope) { IRScope irScope = scope.getScope(); String name = JavaNameMangler.encodeScopeForBacktrace(irScope) + '$' + methodIndex++ + "_IRSCope"; if (scopeMap.get(name) == null) { scopeMap.put(name, irScope); jvm.cls().visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_VOLATILE, name, ci(IRScope.class), null, null).visitEnd(); } jvmAdapter().getstatic(jvm.clsData().clsName, name, ci(IRScope.class)); jvmAdapter().invokestatic(p(Helpers.class), "getStaticScope", sig(StaticScope.class, IRScope.class)); }
public String getNewConstant(String type, String name_prefix, Object init) { ClassVisitor cv = getClassVisitor(); String realName = getNewConstantName(); // declare the field cv.visitField(ACC_PRIVATE, realName, type, null, null).visitEnd(); if(init != null) { initMethod.aload(THIS); initMethod.ldc(init); initMethod.putfield(getClassname(),realName, type); } return realName; }
public void pushDRegexp(Runnable callback, RegexpOptions options, int arity) { if (arity > MAX_ARGUMENTS) throw new NotCompilableException("dynamic regexp has more than " + MAX_ARGUMENTS + " elements"); String cacheField = null; Label done = null; if (options.isOnce()) { // need to cache result forever cacheField = "dregexp" + getClassData().callSiteCount.getAndIncrement(); done = new Label(); adapter.getClassVisitor().visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, cacheField, ci(RubyRegexp.class), null, null).visitEnd(); adapter.getstatic(getClassData().clsName, cacheField, ci(RubyRegexp.class)); adapter.dup(); adapter.ifnonnull(done); adapter.pop(); } // We may evaluate these operands multiple times or the upstream instrs that created them, which is a bug (jruby/jruby#2798). // However, only one dregexp will ever come out of the indy call. callback.run(); adapter.invokedynamic("dregexp", sig(RubyRegexp.class, params(ThreadContext.class, RubyString.class, arity)), DRegexpObjectSite.BOOTSTRAP, options.toEmbeddedOptions()); if (done != null) { adapter.dup(); adapter.putstatic(getClassData().clsName, cacheField, ci(RubyRegexp.class)); adapter.label(done); } }
public void pushDRegexp(Runnable callback, RegexpOptions options, int arity) { if (arity > MAX_ARGUMENTS) throw new NotCompilableException("dynamic regexp has more than " + MAX_ARGUMENTS + " elements"); String cacheField = null; Label done = null; if (options.isOnce()) { // need to cache result forever cacheField = "dregexp" + getClassData().callSiteCount.getAndIncrement(); done = new Label(); adapter.getClassVisitor().visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, cacheField, ci(RubyRegexp.class), null, null).visitEnd(); adapter.getstatic(getClassData().clsName, cacheField, ci(RubyRegexp.class)); adapter.dup(); adapter.ifnonnull(done); adapter.pop(); } // We may evaluate these operands multiple times or the upstream instrs that created them, which is a bug (jruby/jruby#2798). // However, only one dregexp will ever come out of the indy call. callback.run(); adapter.invokedynamic("dregexp", sig(RubyRegexp.class, params(ThreadContext.class, RubyString.class, arity)), DRegexpObjectSite.BOOTSTRAP, options.toEmbeddedOptions()); if (done != null) { adapter.dup(); adapter.putstatic(getClassData().clsName, cacheField, ci(RubyRegexp.class)); adapter.label(done); } }
if (scopeMap.get(scopeField) == null) { scopeMap.put(scopeField, scope); jvm.cls().visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_VOLATILE, scopeField, ci(IRScope.class), null, null).visitEnd();