javaagent: adding new classes

View: New views
1 Messages — Rating Filter:   Alert me  

javaagent: adding new classes

by alarmnummer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have the following problem and hope that someone is able to point me
in the right direction.

I'm building an STM and if there is an atomic object Foo, I need a
Foo_Tranlocal and Foo_TranlocalSnap to be created. I already have this
system up and running but I needed to do some hacks to add the new
classes to the classloader. I created a new ClassLoader that is in the
package java.lang and is able to access methods that else would be
inaccessible. This new classloader needs to be placed in the
bootclasspath because it is in a 'dangerous' package. So I want to get
rid of this approach.

So I decided to write my own classloader and it looks something like this:

public class MultiverseClassLoader extends ClassLoader {

    public MultiverseClassLoader(ClassLoader parent) {
        super(parent);
        System.out.println("Multiverse ClassLoader created");
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        if (name.endsWith("__Tranlocal")) {
            String baseName = getBaseName(name, "__Tranlocal");
            return defineTranlocal(baseName, name);
        } else if (name.endsWith("__TranlocalSnapshot")) {
            String baseName = getBaseName(name, "__TranlocalSnapshot");
            return defineTranlocalSnapshot(baseName, name);
        } else if (name.endsWith("__AtomicTemplate")) {
            return defineAtomicTemplate(name);
        } else {
            throw new ClassNotFoundException(name);
        }
    }


So when a request for a Tranlocal or TranslocalSnapshot or
AtomicTemplate comes, the system knows what code need to be generated.
This classloader is installed using the following parameter on the
commandline:
-Djava.system.class.loader=org.multiverse.stms.alpha.instrumentation.MultiverseClassLoade

The big problem is that this doesn't work and I don't see any requests
for __Tranlocal/__TranlocalSnapshot/__AtomicTemplate comming by, even
though I get a NoClassDefFoundError:

java.lang.NoClassDefFoundError:
org/multiverse/stms/alpha/instrumentation/integrationtest/IntRef__Tranlocal
        at org.multiverse.stms.alpha.instrumentation.integrationtest.IntRefTest.test(IntRefTest.java:17)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
        at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
        at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
        at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)

So apparently the classloader I created is not the one that is loading
my classes. And I can confirm this, because when I print the
classloader  used to load IntRef, I don't see a MultiverseClassLoader,
but I see a sun.misc.Launcher$AppClassLoader

I guess a lot of people using javaagents have encountered the same
problems and I hope that one of you is able to tell me how to fix this
issue: how to add newly created bytecode to the classloader.


--
You receive this message as a subscriber of the asm@... mailing list.
To unsubscribe: mailto:asm-unsubscribe@...
For general help: mailto:sympa@...?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws