Examples of JiapiClass


Examples of alt.jiapi.reflect.JiapiClass

    }

    public void instrument(JiapiMethod jm) {
        InstructionList il = jm.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();
        JiapiClass mep = getEventProducer();
        JiapiMethod methodEntered = null;
        JiapiMethod methodExited = null;
        JiapiField jiapiField = getEventProducerField();

        // a flag, that tells whether or not InstructionList being
        // processed is in a static method.
        boolean isStatic = Modifier.isStatic(il.getDeclaringMethod().getModifiers());

        try {
            methodEntered =
                mep.getDeclaredMethod("methodEntered",
                                      new String[] { "java.lang.Object",
                                                     "java.lang.String" });
            methodExited =
                mep.getDeclaredMethod("methodExited",
                                      new String[] { "java.lang.Object",
                                                     "java.lang.String" });
        }
        catch(Exception e) {
            System.out.println("ERROR: " + e);
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

            }
        }
    }

    protected JiapiClass getEventProducer() {
        JiapiClass jc = null;
        try {
            jc = new Loader().loadClass(ep.getClass().getName());
        }
        catch(Exception e) {
            System.out.println("ERROR: " + e);
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

        InstructionList il = clinit.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();
        InstructionList initializer = il.createEmptyList();

        try {
            JiapiClass er = currentClass.getLoader().loadClass("alt.jiapi.event.EventRuntime");
            JiapiMethod gfv =
                er.getDeclaredMethod("getFieldValue",
                                     new String[] {"java.lang.String"});

            // Get the field value from runtime
            initializer.add(factory.pushConstant(fieldName));
            initializer.add(factory.invoke(gfv));
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

        HSInstrumentor(HotSpotAdvice advice, byte[] hotSpots, String resolution) {
            try {
                this.rule = new Rule(resolution);
                Loader l = new Loader();
                log.debug("Loading advice " + advice.getClass().getName());
                JiapiClass clazz = l.loadClass(advice.getClass().getName());

                log.debug("Getting advice() method ");
                this.adviceMethod =
                    clazz.getDeclaredMethod("advice", new String[0]);
                this.hotSpots = hotSpots;
            }
            catch(NoSuchMethodException nsme) {
                // Should not happen, since it is an abstract method and
                // there has to be an implementation for it.
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

            throw new NullPointerException("Got null factory");
        }

        int currentMethodModifiers = il.getDeclaringMethod().getModifiers();

        JiapiClass clazz = getCurrentClass();
        Class[] hookParams = hookMethod.getParameterTypes();

        if (isDynamic) {
            log.debug("Hook is dynamic");
            // Obtain a field, that holds a reference to the method
            // to be called.
            JiapiField field = null;
            try {
                field = clazz.getDeclaredField(jiapiFieldName);
            }
            catch (NoSuchFieldException nsfe) {
                throw new JiapiRuntimeException("No such field: " + nsfe.getMessage());
            }

            il.add(factory.getField(field));

            if (Modifier.isStatic(currentMethodModifiers)) {
                il.add(factory.pushConstant(clazz.getName()));
            }
            else {
                il.add(factory.pushThis()); // First argument is 'this'
            }
        }
        else {
            log.debug("Hook is static");
            // On static methods, First argument is name of the current class.
            // This should be Class object.
            // Runtime.forName(clazz.getName())
            // factory.forName(clazz.getName())
            il.add(factory.pushConstant(clazz.getName()));
        }

        // Skip first param (source object made above)
        for (int i = 1; i < hookParams.length; i++) {
            if (hookParams[i].equals(String.class)) {
                // ---  target name  ---
                String targetName = instrumentation.getTargetName();
                if (targetName == null) {
                    targetName = "???";
                }

                il.add(factory.pushConstant(targetName));
            }
            else if (hookParams[i].equals(Object.class)) {
                // ---  target Object  ---
                InstructionList targetCode = instrumentation.getTargetCode();
                if (targetCode != null) {
                    log.debug("Got target code: " + targetCode);
                    il.add(targetCode);
                }
                else {
                    log.debug("No target code");
                    il.add(factory.pushNull());
                }
            }
            else if (hookParams[i].equals(Object[].class)) {
                // ---  target Object[]  ---
                log.warn("target arguments are not supported");
                il.add(factory.pushNull());
            }
            else {
                log.error("Invalid Hook method: " + hookMethod);
            }
        }

        Loader l = new Loader();
        try {
            JiapiClass hClass = l.loadClass(hookClass.getName());
            Class[] hpTypes = hookMethod.getParameterTypes();
            String[] pTypes = new String[hpTypes.length];
           
            for (int i = 0; i < pTypes.length; i++) {
                pTypes[i] = hpTypes[i].getName();
            }
           
            JiapiMethod hMethod =hClass.getDeclaredMethod(hookMethod.getName(),
                                                          pTypes);
            il.add(factory.invoke(hMethod));
        }
        catch(Exception e) {
            log.error("Failed to add invoke instruction: " + e);
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

            log.info("Will not pre instrument for static calls");
            // Static calls don't need any helper instrumentors.
            return null;
        }

        JiapiClass c = getCurrentClass();

        // Make sure pre instrumentation is done only once per JiapiClass
        if (preInstrumentations.containsKey(c)) {
            return null;
        }
        else {
            preInstrumentations.put(c, null);
        }
       
        int modifiers = c.getModifiers();
        if (Modifier.isInterface(modifiers)) {
            log.info("Will not pre instrument interface " + c.getName());
            return null;
        }

        preChain = new InstrumentorChain();
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

        if (!isDynamic) {
            // Static calls don't need any helper instrumentors.
            return null;
        }

        JiapiClass c = getCurrentClass();
        // Make sure pre instrumentation is done only once per JiapiClass
        if (postInstrumentations.containsKey(c)) {
            return null;
        }
        else {
            postInstrumentations.put(c, null);
        }

        int modifiers = c.getModifiers();
        if (Modifier.isInterface(modifiers)) {
            log.info("Will not post instrument interface " + c.getName());
            return null;
        }

        postChain = new InstrumentorChain();
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

    protected synchronized Class loadClass(String className, boolean resolve)
        throws ClassNotFoundException {
        //System.out.println("Loading " + className);

        Class cl = null;
        JiapiClass jiapiClass = null;
        log.debug("loadClass(" + className + ")");
//         System.out.println("loadClass(" + className + ")");

        // Core Java classes and Jiapi classes are delegated to parent
        // class loader.
        if (className.startsWith("java.") || className.startsWith("javax.") ||
            className.startsWith("sun.") || className.startsWith("alt.jiapi.")) {
//       System.out.println("getParent().loadClass(" + className + ")" +
//     getParent());
            return getParent().loadClass(className);
        }

        if ((cl = (Class) classes.get(className)) == null) {
            log.debug("cache miss: " + className);
            // Check if we have permission to access the package.
            SecurityManager sm = System.getSecurityManager();
            if (sm != null) {
                int i = className.lastIndexOf('.');
                if (i != -1) {
                    sm.checkPackageAccess(className.substring(0, i));
                }
            }

            if (ctx == null) {
                return bootstrap(className);
            }
           
            // Locate the class as a resource.
            String path = className.replace('.', '/').concat(".class");
            URL location = super.findResource(path);

            if (location == null) {
                // Delagate to parent.

                return getParent().loadClass(className);
            }

            try {
                jiapiClass = ctx.getLoader().loadClass(className, location);
            }
            catch(java.io.IOException ioe) {
                throw new ClassNotFoundException(className);
            }

            ctx.instrument(jiapiClass);

            byte[] bytes = jiapiClass.getByteCode();

            if (System.getProperty("dump") != null) {
                try {
                    jiapiClass.dump(new java.io.FileOutputStream(jiapiClass.getName() + ".dump"));
                }
                catch(Throwable t) {
                }
            }
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

    public AddInterfaceInstrumentor(String[] interfaceNames) {
        this.interfaceNames = interfaceNames;
    }

    public void instrument(InstructionList il) {
        JiapiClass clazz = getCurrentClass();

        for (int i = 0; i < interfaceNames.length; i++) {
            clazz.addInterface(interfaceNames[i]);
        }

        forward(il);
    }
View Full Code Here

Examples of alt.jiapi.reflect.JiapiClass

    public MethodDispatcherInstrumentor() {
    }

    public void instrument(InstructionList il) {
        JiapiClass clazz = getCurrentClass();
        JiapiMethod[] methods = clazz.getDeclaredMethods();

        for (int i = 0; i < methods.length; i++) {
            log.debug("dispatching for: " + methods[i].getName());
            InstructionList _il = methods[i].getInstructionList();
            forward(_il);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.