| Method from org.codehaus.groovy.runtime.callsite.CallSiteGenerator Detail: |
public static Constructor compilePogoMethod(CachedMethod cachedMethod) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final CachedClass declClass = cachedMethod.getDeclaringClass();
final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
final byte[] bytes = genPogoMetaMethodSite(cachedMethod, cw, name);
return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
|
public static Constructor compilePojoMethod(CachedMethod cachedMethod) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final CachedClass declClass = cachedMethod.getDeclaringClass();
final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
final byte[] bytes = genPojoMetaMethodSite(cachedMethod, cw, name);
return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
|
public static Constructor compileStaticMethod(CachedMethod cachedMethod) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final CachedClass declClass = cachedMethod.getDeclaringClass();
final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
final byte[] bytes = genStaticMetaMethodSite(cachedMethod, cw, name);
return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
|
public static void genCallWithFixedParams(ClassWriter cw,
String name,
String superClass,
CachedMethod cachedMethod,
String receiverType) {
if (cachedMethod.getParamsCount() > 4) return;
StringBuilder pdescb = new StringBuilder();
final int pc = cachedMethod.getParamsCount();
for (int i = 0; i != pc; ++i) pdescb.append("Ljava/lang/Object;");
writeMethod(cw,name,pc+2,superClass,cachedMethod,receiverType,pdescb.toString(),false);
}
|
public static void genCallXxxWithArray(ClassWriter cw,
String name,
String superClass,
CachedMethod cachedMethod,
String receiverType) {
writeMethod(cw,name,3,superClass,cachedMethod,receiverType,"[Ljava/lang/Object;",true);
}
|
public static byte[] genPogoMetaMethodSite(CachedMethod cachedMethod,
ClassWriter cw,
String name) {
MethodVisitor mv;
cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name.replace('.','/'), null, "org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite", null);
genConstructor(cw, "org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite");
genCallXxxWithArray(cw, "Current", "org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite", cachedMethod, "groovy/lang/GroovyObject");
genCallXxxWithArray(cw, "", "org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite", cachedMethod, "java/lang/Object");
genCallWithFixedParams(cw, "Current", "org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite", cachedMethod, "groovy/lang/GroovyObject");
genCallWithFixedParams(cw, "", "org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite", cachedMethod, "java/lang/Object");
cw.visitEnd();
return cw.toByteArray();
}
|
public static byte[] genPojoMetaMethodSite(CachedMethod cachedMethod,
ClassWriter cw,
String name) {
MethodVisitor mv;
cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name.replace('.','/'), null, "org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite", null);
genConstructor(cw, "org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite");
genCallXxxWithArray(cw, "", "org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite", cachedMethod, "java/lang/Object");
genCallWithFixedParams(cw, "", "org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite", cachedMethod, "java/lang/Object");
cw.visitEnd();
return cw.toByteArray();
}
|
public static byte[] genStaticMetaMethodSite(CachedMethod cachedMethod,
ClassWriter cw,
String name) {
cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name.replace('.','/'), null, "org/codehaus/groovy/runtime/callsite/StaticMetaMethodSite", null);
genConstructor(cw, "org/codehaus/groovy/runtime/callsite/StaticMetaMethodSite");
genCallXxxWithArray(cw, "", "org/codehaus/groovy/runtime/callsite/StaticMetaMethodSite", cachedMethod, "java/lang/Object");
genCallXxxWithArray(cw, "Static", "org/codehaus/groovy/runtime/callsite/StaticMetaMethodSite", cachedMethod, "java/lang/Class");
genCallWithFixedParams(cw, "", "org/codehaus/groovy/runtime/callsite/StaticMetaMethodSite", cachedMethod, "java/lang/Object");
genCallWithFixedParams(cw, "Static", "org/codehaus/groovy/runtime/callsite/StaticMetaMethodSite", cachedMethod, "java/lang/Class");
cw.visitEnd();
return cw.toByteArray();
}
|
public static boolean isCompilable(CachedMethod method) {
return GroovySunClassLoader.sunVM != null || Modifier.isPublic(method.cachedClass.getModifiers()) && method.isPublic() && publicParams(method);
}
|