void processMethods() throws IOException { int methodsCount = is.readUnsignedShort(); os.writeShort(methodsCount); for (int i = 0; i < methodsCount; i++) { MethodInfo methodInfo = readMethod(); if (methodInfo.getInterceptorClass() != null) { injectCode(methodInfo); } methods.add(methodInfo); } writeMethods(); }
private void injectCode(MethodInfo methodInfo) throws IOException { if (methodInfo.getCode() == null) { return; } InterceptorConstants interceptorConstants = getOrInsertInterceptorConstants(methodInfo.getInterceptorClass()); fixupSignature(methodInfo.getSignature()); Map<String, Integer> wrapperMethods = getOrInsertPrimitiveWrapperMethods(methodInfo.getSignature()); ByteArrayOutputStream codeToInject = new ByteArrayOutputStream(); InstructionsFacility instructionsFacility = new InstructionsFacility( new DataOutputStream(codeToInject), methodInfo.getSignature(), interceptorConstants, wrapperMethods); instructionsFacility.generateInterceptorInstantiationCode(); instructionsFacility.generateInterceptorMethodParametersCode(getObjectClassIndex()); instructionsFacility.generateObjectArrayFillingCode(); instructionsFacility.generateInterceptorInvocationCode( interceptorConstants.getInterceptorMethod()); Code code = methodInfo.getCode(); int originalStackSize = code.getMaxStack(); code.setMaxStack(Math.max(originalStackSize, instructionsFacility.getStackSizeNeeded())); code.setInjected(codeToInject.toByteArray()); code.refresh(); }