Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-07-04 Thread Rafael Winterhalter
Hi Mandy and Alan, I very much understand your points of view that the Java instrumentation API should retain its original intended scope and that every problem should be solved at its own time. I do however claim that the proposed API does not even solve this problem of auxiliary classes for the

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-07-02 Thread mandy chung
My proposal of ClassDefiner API allows the java agent to define auxiliary classes in the same runtime package of the class being instrumented. You raised other use cases that are not addressed by this proposal. As Alan replied, the ability to define any arbitrary class would be an attractive

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-07-02 Thread Alan Bateman
On 02/07/2018 09:41, Rafael Winterhalter wrote: Hi, I was wondering if a solution for this problem is still planned for JDK 11 giving the beginning ramp down. With removing sun.misc.Unsafe::defineClass, Java agents only have an option to use jdk.internal.misc.Unsafe::defineClass for the

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-07-02 Thread Rafael Winterhalter
Hi, I was wondering if a solution for this problem is still planned for JDK 11 giving the beginning ramp down. With removing sun.misc.Unsafe::defineClass, Java agents only have an option to use jdk.internal.misc.Unsafe::defineClass for the use-cases that I described. I think it would be a

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-05-30 Thread Rafael Winterhalter
Hei Mandy, yes, this sums it up, I think and I have worked with all use cases where sun.misc.Unsafe::defineClass is more then sufficient. One major issue I also have with the current API are the costs in refactoring existing agents, especially since one would need to deliver a seperate agent for

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-05-29 Thread mandy chung
Hi Rafael, Thanks for the additional use cases of Unsafe::defineClass and looking through many different agents to identify their migration path. Summarize the requirements you collected (please correct/add): 1. need a means to define auxiliary classes in the same runtime package of an

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-05-29 Thread Rafael Winterhalter
Hei Mandy, after further investigation I have found several other use cases of sun.misc.Unsafe::defineClass for which the proposal for JDK-8200559 would not currently offer a solution. I will try to describe a generic case of the problem I found: Java agents sometimes need to communicate state

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-23 Thread Alan Bateman
On 15/04/2018 07:23, mandy chung wrote: This proposal would allow java agents to migrate from internal API and ClassDefiner to be enhanced in the future. Webrev: http://cr.openjdk.java.net/~mchung/jdk11/webrevs/8200559/webrev.00/ I went through the proposed spec/API addition and it looks

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-18 Thread mandy chung
https://bugs.openjdk.java.net/browse/JDK-8201784 This is the correct JBS issue (Sorry I cut-n-paste the wrong link). Mandy On 4/18/18 3:46 PM, mandy chung wrote: Hi Rafael, I think it's best to separate the testing requirement from java agents doing instrumentation that may run in

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-18 Thread Rafael Winterhalter
Hei Mandy, Generally I agree with you that these two should be seperate but I think that there is a very blurry border between the two. Java agents are sometimes used to test something in a production environment and there is a long history of agent development that relies on the easy and general

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-18 Thread mandy chung
Hi Rafael, I think it's best to separate the testing requirement from java agents doing instrumentation that may run in production environment. I have created a JBS issue to track the testing mode idea that would require more discussion and investigation:  

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-17 Thread Rafael Winterhalter
Hei Mandy, Lookup::defineClass would always be an alternative but it would require me to open the class first. If the instrumented type can read the module with the callback but its module was not opened, this would not help me much, unfortunately. Also, I could not resolve this lookup as the

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-17 Thread mandy chung
Hi Rafael, I see that mocking/proxying/testing framework should be looked at separately since its requirements and approaches can be different than tool agents. On 4/17/18 5:06 AM, Rafael Winterhalter wrote: Hei Mandy, I have looked into several Java agents that I have worked on and for

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-16 Thread Rafael Winterhalter
Hei Mandy, I have looked into several Java agents that I have worked on and for many of them, this API does unfortunately not supply sufficient access. I would therefore still prefer a method Instrumentation::defineClass. The problem is that some agents need to define classes in other packages

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-16 Thread Alan Bateman
On 16/04/2018 08:11, Rafael Winterhalter wrote: : I also think it is essential to being able to inject a class into a non-opened package. Otherwise one could use a method handle. When instrumenting classes one already has full privilege for all packages as an agent can open modules. If one

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-16 Thread Rafael Winterhalter
Hi David, >From my perspective as a heavy user of this API in Unsafe today: >From my experience, the recursive dependency is not a common problem as auxiliary types normally only reference the instrumented type. Beyond, this problem is an issue for such explicit dynamic class loading, also when

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-16 Thread mandy chung
On 4/16/18 2:13 PM, David Holmes wrote: Hi Mandy, How do you handle dependencies across a set of auxiliary types, i.e if you are defining a new class A, and it depends on B (which you also intend to define), how will the classloader resolve references from A to B when it can't load B

Re: Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-16 Thread David Holmes
Hi Mandy, How do you handle dependencies across a set of auxiliary types, i.e if you are defining a new class A, and it depends on B (which you also intend to define), how will the classloader resolve references from A to B when it can't load B itself? Is the key capability here the ability

Review Request JDK-8200559: Java agents doing instrumentation need a means to define auxiliary classes

2018-04-15 Thread mandy chung
Background: Java agents support both load time and dynamic instrumentation. At load time, the agent's ClassFileTransformer is invoked to transform class bytes.  There is no Class objects at this time.  Dynamic instrumentation is when redefineClasses or retransformClasses is used to redefine