Adding fields to java.lang.Object

Hi,

Is anybody aware of any restriction that prevents me from adding a new field

to java.lang.Object? I tried both using JVMTI or adding the transformed class to rt.jar and all i get is this

java.lang.IllegalStateException

at java.lang.Throwable.initCause(Throwable.java:320)

at java.lang.ExceptionInInitializerError.<init>(ExceptionInInitializerError.java:62)

[403 byte] By [genadya] at [2007-11-26 13:35:09]
# 1
and I should add that if I apply the same transformation to another class (like java.util.Date) it works just fine.
genadya at 2007-7-7 22:17:54 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
At least in the HotSpot VM, I believe we have assumptions on the size of Object and that probably explains the strange exception you are seeing. You should be able to instrument the Object construct and there are existing agents that do that.
alan.batemana at 2007-7-7 22:17:54 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
Thanks Alan,Are there any other classes that I should rather not touch?
genadya at 2007-7-7 22:17:54 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

I believe we have a number of classes where it would be problematic if you changed the ordering of fields (meaning it should be okay to add to the end but don't change the order of existing fields). These classes would be: java.lang.String, java.lang.Class, java.lang.Throwable, java.lang.ref.Reference, java.lang.ref.SoftReference, java.lang.ClassLoader, java.lang.System, and java.lang.StackTraceElement.

BTW: Instrumentation is usually used to inject hooks into existing byte codes - is there a reason why you want to add fields?

alan.batemana at 2007-7-7 22:17:54 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

Thanks again!

I'm trying to do some experiments that require attaching an integer to each object and modifying it frequently as the program runs. I've read about tags, but if I understand it correctly, I can only use tags in the native code, which would be unreasonable performance hit.

genadya at 2007-7-7 22:17:54 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...