load external classes

68 views
Skip to first unread message

Gabriel Ferreira

unread,
Nov 26, 2013, 11:34:10 AM11/26/13
to reflecta...@googlegroups.com
Hi. I have two questions.

1) Is there any reflectasm .jar, or do i have to build it from the downloaded project?

2) I downloaded the reflectasm project and built my own .jar. Then, i imported the .jar on a normal Netbeans project. I tried to use MethodAccess with a class that i created on my project:

MethodAccess access = MethodAccess.get(ModelClass.class);

But i got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassWriter
    at com.esotericsoftware.reflectasm.FieldAccess.get(FieldAccess.java:108)
    at pack2.ReflectTest.main(ReflectTest.java:29)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassWriter

Then, i opened the reflectasm project on Eclipse, and i created a main class and a model class for test purposes, inside the project, and it worked.

As far as i understood, the problem is the class loader. So, if i want my classes working with an reflectasm .jar, do i need to modify the AccessClassLoader (or create my own classloader)?

---

By the way, my sugestion is byte class loader. So, it would allows to load classes from data bytes.

Best regards, and congratz for your project guys :)
Gabriel.

Nate

unread,
Nov 26, 2013, 5:19:13 PM11/26/13
to reflecta...@googlegroups.com
On Tue, Nov 26, 2013 at 5:34 PM, Gabriel Ferreira <gabri...@gmail.com> wrote:
Hi. I have two questions.

1) Is there any reflectasm .jar, or do i have to build it from the downloaded project?

 

2) I downloaded the reflectasm project and built my own .jar. Then, i imported the .jar on a normal Netbeans project. I tried to use MethodAccess with a class that i created on my project:

MethodAccess access = MethodAccess.get(ModelClass.class);

But i got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassWriter
    at com.esotericsoftware.reflectasm.FieldAccess.get(FieldAccess.java:108)
    at pack2.ReflectTest.main(ReflectTest.java:29)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassWriter

You need the ObjectWeb ASM JAR (in the reflectasm lib dir).

-Nate

Message has been deleted

Gabriel Ferreira

unread,
Nov 27, 2013, 12:31:13 PM11/27/13
to reflecta...@googlegroups.com
Thanks for your support :)

Nate

unread,
Dec 2, 2013, 4:41:22 AM12/2/13
to reflecta...@googlegroups.com

On Wed, Nov 27, 2013 at 6:25 PM, Gabriel Ferreira <gabri...@gmail.com> wrote:
Hi. Thanks for your support.
By the way, i observed something that i can't understand.

I'm trying to measure the time spent on invoking 7 methods (all do the same, but have different names) from my own model class, using MethodAccess.

For this test, i used 2 similar ways to invoke all methods, shown below:

#1
---
        long start_time = System.currentTimeMillis();
        MethodAccess access = MethodAccess.get(ModelClass.class);
        for(int i = 0; i < N_INSTANCES; i++) {
            for(String str: access.getMethodNames()) {
                access.invoke(objects[i], str, array[i]);
            }
        }
        long end_time = System.currentTimeMillis();
---

#2
---
        long start_time = System.currentTimeMillis();
        MethodAccess access = MethodAccess.get(ModelClass.class);
        for(int i = 0; i < N_INSTANCES; i++) {
            for(String str: access.getMethodNames()) {
                int index = access.getIndex(str);
                access.invoke(objects[i], index, array[i]);
            }
        }
        long end_time = System.currentTimeMillis();
---

The only difference between these two methods it's the invoke with method index, and the invoke with method name. These are the timers i've got:

elapsed: 48 [#1]
elapsed: 13 [#2]

(where elapsed = end_time - start_time)

But i noticed that the invoke method using method name, actually, only calls the invoke with index, as u can see below:

    public Object invoke (Object object, String methodName, Object... args) {
        return invoke(object, getIndex(methodName), args);
    }
(source obtained on MethodAccess.java)

Why am i getting these variance of elapsed time?

Because getIndex does a bunch of string comparison to get the index. :)

-Nate


Reply all
Reply to author
Forward
0 new messages