Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First an explanation without ClassFileTransformer:</p> <p>The license of the Oracle JRE/JDK includes that you cannot change java.* packages, and from what you've shown with your test of trying to change something in java.lang, they've included a test and throw a security exception if you try.</p> <p>With that said, you can change the behavior of system classes by compiling an alternative and referencing it using the JRE -Xbootclasspath/p CLI option.</p> <p>After looking at what you can achieve through that method, I expect you will have to work more and compile a custom version of the OpenJDK. I expect this because the Bootstrap classloader is (from what I've read) a native implementation.</p> <p>See <a href="http://onjava.com/pub/a/onjava/2005/01/26/classloading.html" rel="noreferrer">http://onjava.com/pub/a/onjava/2005/01/26/classloading.html</a> for my favorite overview of classloaders.</p> <p>Now with ClassFileTransformer:</p> <p>As you've shown, you can update the method programs (and some specific other aspects of pre-loaded classes). In response to the questions you've asked:</p> <p>Instrumenting on demand: what's important here is that every loaded class has a unique Class instance associated with it; so if you want to target a specific loaded class you'll have to note what instance that is, and this can be found through various ways including the member, 'class', associated with every class name, like Object.class.</p> <p>Is it threadsafe: no, two threads could be changing the set concurrently, and you can solve this problem in many ways; I suggest using a concurrent version of Set.</p> <p>Globals etc: I think globals specifically are necessary (I think your implementation could be done a little better), but chances are there won't be problems, and you'll learn how to code better for Java later (I've coded for about 12 years now, and you wouldn't believe some subtle things about using the language).</p> <p>Metadata in Class instances: of all the time I've used Java, attaching metadata has not been natural, and probably for good reason; keeping a map for the specific purpose is fine, and remember it's only a map between the pointer to the instance, and the metadata, so it's not really a memory hog.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload