Class ConstructorInstrumenter

    • Method Detail

      • instrumentClass

        public static void instrumentClass​(Class<?> c,
                                           ConstructorCallback<?> sampler)
                                    throws UnmodifiableClassException
        Ensures that the given sampler will be invoked every time a constructor for class c is invoked.
        Parameters:
        c - The class to be tracked
        sampler - the code to be invoked when an instance of c is constructed
        Throws:
        UnmodifiableClassException - if c cannot be modified.
      • instrument

        public static byte[] instrument​(byte[] originalBytes,
                                        Class<?> classBeingRedefined)
        Given the bytes representing a class, add invocations of the ConstructorCallback method to the constructor.
        Parameters:
        originalBytes - the original byte[] code.
        classBeingRedefined - the class being redefined.
        Returns:
        the instrumented byte[] code.
      • invokeSamplers

        public static void invokeSamplers​(Object o)
        Bytecode is rewritten to invoke this method; it calls the sampler for the given class. Note that, unless the javaagent command line argument "subclassesAlso" is specified, it won't do anything if o is a subclass of the class that was supposed to be tracked.
        Parameters:
        o - the object passed to the samplers.