use of org.mvel2.asm.MethodVisitor in project mvel by mikebrock.
the class ASMAccessorOptimizer method _initJIT.
/**
* Does all the boilerplate for initiating the JIT.
*/
private void _initJIT() {
if (isAdvancedDebugging()) {
buildLog = new StringAppender();
}
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
synchronized (Runtime.getRuntime()) {
cw.visit(OPCODES_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className = "ASMAccessorImpl_" + valueOf(cw.hashCode()).replaceAll("\\-", "_") + (System.currentTimeMillis() / 10) + ((int) Math.random() * 100), null, "java/lang/Object", new String[] { NAMESPACE + "compiler/Accessor" });
}
MethodVisitor m = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
m.visitCode();
m.visitVarInsn(Opcodes.ALOAD, 0);
m.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
m.visitInsn(RETURN);
m.visitMaxs(1, 1);
m.visitEnd();
(mv = cw.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/Object;Ljava/lang/Object;L" + NAMESPACE + "integration/VariableResolverFactory;)Ljava/lang/Object;", null, null)).visitCode();
}
use of org.mvel2.asm.MethodVisitor in project mvel by mikebrock.
the class ASMAccessorOptimizer method buildInputs.
private void buildInputs() {
if (compiledInputs.size() == 0)
return;
assert debug("\n{SETTING UP MEMBERS...}\n");
StringAppender constSig = new StringAppender("(");
int size = compiledInputs.size();
for (int i = 0; i < size; i++) {
assert debug("ACC_PRIVATE p" + i);
cw.visitField(ACC_PRIVATE, "p" + i, "L" + NAMESPACE + "compiler/ExecutableStatement;", null, null).visitEnd();
constSig.append("L" + NAMESPACE + "compiler/ExecutableStatement;");
}
constSig.append(")V");
assert debug("\n{CREATING INJECTION CONSTRUCTOR}\n");
MethodVisitor cv = cw.visitMethod(ACC_PUBLIC, "<init>", constSig.toString(), null, null);
cv.visitCode();
assert debug("ALOAD 0");
cv.visitVarInsn(ALOAD, 0);
assert debug("INVOKESPECIAL java/lang/Object.<init>");
cv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
for (int i = 0; i < size; i++) {
assert debug("ALOAD 0");
cv.visitVarInsn(ALOAD, 0);
assert debug("ALOAD " + (i + 1));
cv.visitVarInsn(ALOAD, i + 1);
assert debug("PUTFIELD p" + i);
cv.visitFieldInsn(PUTFIELD, className, "p" + i, "L" + NAMESPACE + "compiler/ExecutableStatement;");
}
assert debug("RETURN");
cv.visitInsn(RETURN);
cv.visitMaxs(0, 0);
cv.visitEnd();
assert debug("}");
}
use of org.mvel2.asm.MethodVisitor in project mvel by mikebrock.
the class ASMAccessorOptimizer method _initJIT2.
private void _initJIT2() {
if (isAdvancedDebugging()) {
buildLog = new StringAppender();
}
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
synchronized (Runtime.getRuntime()) {
cw.visit(OPCODES_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className = "ASMAccessorImpl_" + valueOf(cw.hashCode()).replaceAll("\\-", "_") + (System.currentTimeMillis() / 10) + ((int) Math.random() * 100), null, "java/lang/Object", new String[] { NAMESPACE + "compiler/Accessor" });
}
MethodVisitor m = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
m.visitCode();
m.visitVarInsn(Opcodes.ALOAD, 0);
m.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
m.visitInsn(RETURN);
m.visitMaxs(1, 1);
m.visitEnd();
(mv = cw.visitMethod(ACC_PUBLIC, "setValue", "(Ljava/lang/Object;Ljava/lang/Object;L" + NAMESPACE + "integration/VariableResolverFactory;Ljava/lang/Object;)Ljava/lang/Object;", null, null)).visitCode();
}
use of org.mvel2.asm.MethodVisitor in project mvel by mikebrock.
the class TraceClassVisitor method visitMethod.
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
buf.setLength(0);
buf.append('\n');
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
buf.append(tab).append("// DEPRECATED\n");
}
buf.append(tab).append("// access flags ").append(access).append('\n');
if (signature != null) {
buf.append(tab);
appendDescriptor(METHOD_SIGNATURE, signature);
TraceSignatureVisitor v = new TraceSignatureVisitor(0);
SignatureReader r = new SignatureReader(signature);
r.accept(v);
String genericDecl = v.getDeclaration();
String genericReturn = v.getReturnType();
String genericExceptions = v.getExceptions();
buf.append(tab).append("// declaration: ").append(genericReturn).append(' ').append(name).append(genericDecl);
if (genericExceptions != null) {
buf.append(" throws ").append(genericExceptions);
}
buf.append('\n');
}
buf.append(tab);
appendAccess(access);
if ((access & Opcodes.ACC_NATIVE) != 0) {
buf.append("native ");
}
if ((access & Opcodes.ACC_VARARGS) != 0) {
buf.append("varargs ");
}
if ((access & Opcodes.ACC_BRIDGE) != 0) {
buf.append("bridge ");
}
buf.append(name);
appendDescriptor(METHOD_DESCRIPTOR, desc);
if (exceptions != null && exceptions.length > 0) {
buf.append(" throws ");
for (int i = 0; i < exceptions.length; ++i) {
appendDescriptor(INTERNAL_NAME, exceptions[i]);
buf.append(' ');
}
}
buf.append('\n');
text.add(buf.toString());
TraceMethodVisitor tcv = createTraceMethodVisitor();
text.add(tcv.getText());
if (cv != null) {
tcv.mv = cv.visitMethod(access, name, desc, signature, exceptions);
}
return tcv;
}
Aggregations