public MIDletClassLoader(ClassLoader parent) { super(new URL[] {}, parent); noPreporcessingNames = new HashSet(); acc = AccessController.getContext(); config = new InstrumentationConfig(); config.setEnhanceCatchBlock(enhanceCatchBlock); config.setEnhanceThreadCreation(true); }
public void visitLabel(Label label) { if (config.isEnhanceCatchBlock() && catchInfo != null) { CatchInformation newHandler = (CatchInformation)catchInfo.get(label); if (newHandler != null) { mv.visitLabel(newHandler.label); // no push, just use current Throwable in stack mv.visitMethodInsn(INVOKESTATIC, INJECTED_CLASS, "handleCatchThrowable", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;"); // stack contains Throwable, just verify that it is right type for this handler mv.visitTypeInsn(CHECKCAST, newHandler.type); } } mv.visitLabel(label); }
JarInputStream ijis = null; JarOutputStream jos = null; InstrumentationConfig config = new InstrumentationConfig(); config.setEnhanceThreadCreation(true); try { jis = new JarInputStream(midletInputUrl.openStream());
public void visitTypeInsn(final int opcode, String desc) { if ((opcode == NEW) && (config.isEnhanceThreadCreation())) { if ("java/util/Timer".equals(desc)) { desc = codeName(MIDletTimer.class); } else if ("java/util/TimerTask".equals(desc)) { desc = codeName(MIDletTimerTask.class); } else if ("java/lang/Thread".equals(desc)) { desc = codeName(MIDletThread.class); } } mv.visitTypeInsn(opcode, desc); }
if ((config.isEnhanceThreadCreation()) && (name.equals("<init>"))) { if (owner.equals("java/util/Timer")) { owner = codeName(MIDletTimer.class);
public void visit(final int version, final int access, final String name, final String signature, String superName, final String[] interfaces) { if ((0xFF & version) >= 49) { String v = (String) javaVersion.get(new Integer(version)); Logger.warn("Loading MIDlet class " + name + " of version " + version + ((v == null) ? "" : (" " + v))); } if (config.isEnhanceThreadCreation()) { if (superName.equals("java/lang/Thread")) { superName = ChangeCallsMethodVisitor.codeName(MIDletThread.class); } else if (superName.equals("java/util/Timer")) { superName = ChangeCallsMethodVisitor.codeName(MIDletTimer.class); } else if (superName.equals("java/util/TimerTask")) { superName = ChangeCallsMethodVisitor.codeName(MIDletTimerTask.class); } } super.visit(version, access, name, signature, superName, interfaces); }
public void visitTryCatchBlock(final Label start, final Label end, final Label handler, final String type) { if (config.isEnhanceCatchBlock() && type != null) { if (catchInfo == null) { catchInfo = new HashMap(); } CatchInformation newHandler = (CatchInformation)catchInfo.get(handler); if (newHandler == null) { newHandler = new CatchInformation(type); catchInfo.put(handler, newHandler); } mv.visitTryCatchBlock(start, end, newHandler.label, type); } else { mv.visitTryCatchBlock(start, end, handler, type); } }