Logo Search packages:      
Sourcecode: visualvm version File versions  Download package

Object [] org::netbeans::lib::profiler::instrumentation::RecursiveMethodInstrumentor::createInstrumentedMethodPack15 (  )  [inline, private]

Create a multi-class packet of instrumented 1.5-style data

Definition at line 460 of file RecursiveMethodInstrumentor.java.

References org::netbeans::lib::profiler::instrumentation::ConstantPoolExtension::getContents(), org::netbeans::lib::profiler::classfile::BaseClassInfo::getLoaderId(), org::netbeans::lib::profiler::classfile::ClassInfo::getMethodIndex(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::getMethodInfo(), org::netbeans::lib::profiler::classfile::ClassInfo::getMethodNames(), org::netbeans::lib::profiler::classfile::ClassInfo::getMethodSignatures(), org::netbeans::lib::profiler::classfile::BaseClassInfo::getName(), org::netbeans::lib::profiler::instrumentation::ConstantPoolExtension::getNEntries(), org::netbeans::lib::profiler::ProfilerEngineSettings::getRuntimeProfilingPoints(), org::netbeans::lib::profiler::instrumentation::ClassManager::getRuntimeProfilingPoints(), org::netbeans::lib::profiler::global::ProfilingSessionStatus::getStartingMethodId(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::hasUninstrumentedMarkerMethods, org::netbeans::lib::profiler::classfile::DynamicClassInfo::hasUninstrumentedRootMethods, org::netbeans::lib::profiler::classfile::DynamicClassInfo::isMethodInstrumented(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::isMethodLeaf(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::isMethodReachable(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::isMethodUnscannable(), org::netbeans::lib::profiler::instrumentation::ClassManager::javaClassForName(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::saveMethodInfo(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::setHasUninstrumentedMarkerMethods(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::setHasUninstrumentedRootMethods(), org::netbeans::lib::profiler::classfile::DynamicClassInfo::setMethodInstrumented(), and org::netbeans::lib::profiler::global::ProfilingSessionStatus::updateInstrMethodsInfo().

Referenced by createInstrumentedMethodPack().

                                                      {
        int reflectMethodClassIdx = -1;

        if (!reflectInvokeInstrumented) {
            // Check if java.lang.reflect.Method is already among classes to instrument
            int idx = 0;

            for (Enumeration e = instrClasses.elements(); e.hasMoreElements(); idx++) {
                DynamicClassInfo clazz = (DynamicClassInfo) e.nextElement();

                if (clazz.getName() == JAVA_LANG_REFLECT_METHOD_SLASHED_CLASS_NAME) {
                    reflectMethodClassIdx = idx;

                    break;
                }
            }

            if (reflectMethodClassIdx == -1) {
                nInstrClasses++;
            }
        }

        String[] instrMethodClasses = new String[nInstrClasses];
        int[] instrClassLoaderIds = new int[nInstrClasses];
        boolean[] instrMethodLeaf = new boolean[nInstrMethods];
        byte[][] replacementClassFileBytes = new byte[nInstrClasses][];
        int methodId = status.getStartingMethodId();
        int classIdx = 0;
        int methodIdx = 0;

        for (Enumeration e = instrClasses.elements(); e.hasMoreElements();) {
            DynamicClassInfo clazz = (DynamicClassInfo) e.nextElement();
            int nMethods = clazz.getMethodNames().length;
            instrMethodClasses[classIdx] = clazz.getName().replace('/', '.').intern(); // NOI18N

            boolean hasRootMethods = clazz.hasUninstrumentedRootMethods();
            boolean hasMarkerMethods = clazz.hasUninstrumentedMarkerMethods();
            DynamicConstantPoolExtension.getCPFragment(clazz, normalInjectionType);

            if (hasRootMethods) {
                DynamicConstantPoolExtension.getCPFragment(clazz, rootInjectionType);
            }

            if (hasMarkerMethods) {
                DynamicConstantPoolExtension.getCPFragment(clazz, markerInjectionType);
            }

            int imInClass = 0;
            byte[][] replacementMethodInfos = new byte[nMethods][];
            RuntimeProfilingPoint[] pointsForClass = getRuntimeProfilingPoints(engineSettings.getRuntimeProfilingPoints(), clazz);

            //System.err.println("CLazz: "+clazz.getName());
            for (int i = 0; i < nMethods; i++) {
                // FIXME: issue 68840: An overriden method overriding with subclass of return type is instrumented twice
                // http://profiler.netbeans.org/issues/show_bug.cgi?id=68840
                // a method whose return type is not exact match as the method which it implements/overrides would be listed
                // and processed twice, leading to double instrumentation

                //System.err.println("Method: "+clazz.getMethodName(i)+" " + clazz.getMethodSignature(i));
                RuntimeProfilingPoint[] points = getRuntimeProfilingPoints(pointsForClass, i);

                if (!clazz.isMethodInstrumented(i)) {
                    if (clazz.isMethodReachable(i) && !clazz.isMethodUnscannable(i)) {
                        clazz.setMethodInstrumented(i);
                        instrMethodLeaf[methodIdx] = clazz.isMethodLeaf(i);
                        //System.err.println(">>>1 For method " + clazz.getName() + "." + clazz.getMethodName(i) + clazz.getMethodSignature(i) + " gonna use methodId = " + methodId);
                        replacementMethodInfos[i] = InstrumentationFactory.instrumentMethod(clazz, i, normalInjectionType,
                                                                                            rootInjectionType,
                                                                                            markerInjectionType, methodId++,
                                                                                            points);
                        clazz.saveMethodInfo(i, replacementMethodInfos[i]);

                        status.updateInstrMethodsInfo(instrMethodClasses[classIdx], clazz.getLoaderId(),
                                                      clazz.getMethodNames()[i], clazz.getMethodSignatures()[i]);
                        imInClass++;
                        methodIdx++;
                    } else if (points.length > 0) {
                        replacementMethodInfos[i] = InstrumentationFactory.instrumentAsProiflePointHitMethod(clazz, i,
                                                                                                             normalInjectionType,
                                                                                                             points);
                        clazz.saveMethodInfo(i, replacementMethodInfos[i]);
                    }
                } else {
                    replacementMethodInfos[i] = clazz.getMethodInfo(i); // Will return the previously instrumented methodInfo
                    imInClass++;
                }
            }

            instrumentServletDoMethods(clazz, replacementMethodInfos);

            if (imInClass > 0) {
                if (hasRootMethods) {
                    clazz.setHasUninstrumentedRootMethods(false);
                }

                if (hasMarkerMethods) {
                    clazz.setHasUninstrumentedMarkerMethods(false);
                }

                DynamicConstantPoolExtension wholeECP = DynamicConstantPoolExtension.getAllAddedCPFragments(clazz);
                int nAddedCPEntries = wholeECP.getNEntries();
                byte[] addedCPContents = wholeECP.getContents();
                replacementClassFileBytes[classIdx] = ClassRewriter.rewriteClassFile(clazz, replacementMethodInfos,
                                                                                     nAddedCPEntries, addedCPContents);
            }

            instrClassLoaderIds[classIdx] = clazz.getLoaderId();
            classIdx++;
        }

        if (!reflectInvokeInstrumented) { // Special instrumentation of java.lang.reflect.Method.invoke()

            DynamicClassInfo clazz = javaClassForName(JAVA_LANG_REFLECT_METHOD_DOTTED_CLASS_NAME, 0);
            int nMethods = clazz.getMethodNames().length;
            byte[][] replacementMethodInfos = new byte[nMethods][];

            if (reflectMethodClassIdx == -1) {
                instrMethodClasses[classIdx] = JAVA_LANG_REFLECT_METHOD_DOTTED_CLASS_NAME;
                instrClassLoaderIds[classIdx] = 0;
            } else {
                classIdx = reflectMethodClassIdx;

                for (int i = 0; i < nMethods; i++) {
                    replacementMethodInfos[i] = clazz.getMethodInfo(i);
                }
            }

            int idx = clazz.getMethodIndex(INVOKE_METHOD_NAME, INVOKE_METHOD_SIGNATURE);
            DynamicConstantPoolExtension.getCPFragment(clazz, INJ_REFLECT_METHOD_INVOKE);

            replacementMethodInfos[idx] = InstrumentationFactory.instrumentAsReflectInvokeMethod(clazz, idx);

            DynamicConstantPoolExtension wholeECP = DynamicConstantPoolExtension.getAllAddedCPFragments(clazz);
            int nAddedCPEntries = wholeECP.getNEntries();
            byte[] addedCPContents = wholeECP.getContents();
            replacementClassFileBytes[classIdx] = ClassRewriter.rewriteClassFile(clazz, replacementMethodInfos, nAddedCPEntries,
                                                                                 addedCPContents);

            clazz.saveMethodInfo(idx, replacementMethodInfos[idx]);
            reflectInvokeInstrumented = true;
        }

        return new Object[] { instrMethodClasses, instrClassLoaderIds, instrMethodLeaf, replacementClassFileBytes };
    }


Generated by  Doxygen 1.6.0   Back to index