Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread David Holmes
On 18/03/2022 10:51 am, Cheng Jin wrote: Hi Raffaello, My concern is why the verification happens even without initialization in the test without mh.invoke() in the main(), which I don't think is covered or explained in the JVM Spec. Put it in another way, my understanding is, when the class

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Raffaello Giulietti
OK, from what I read so far from you is that you were surprised about the order, not about why verification happens even without initialization. Verification is part of linking, which surely must happen before user code (e.g., initialization) is executed, which explains the order. But once

RE: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Cheng Jin
Hi Raffaello, My concern is why the verification happens even without initialization in the test without mh.invoke() in the main(), which I don't think is covered or explained in the JVM Spec. Put it in another way, my understanding is, when the class gets loaded, it is verified which doesn't

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Raffaello Giulietti
Cheng, initialization is the last thing that happens because it's where user provided code gets executed. This has always been this way, as long as I can remember. See the JVMS for the gory details. Greetings Raffaello On 2022-03-18 01:21, Cheng Jin wrote: Hi David, 1) for the test

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Raffaello Giulietti
Sure, which again shows that Test_2 is not initialized by the lookup of the mh but only upon its invocation. Raffaello On 2022-03-18 00:46, David Holmes wrote: Run with -Xlog:class+init=info to see the classes that get initialized and in what order. David On 18/03/2022 5:53 am, Raffaello

RE: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Cheng Jin
Hi David, 1) for the test with mh.invoke() in main(), the log shows: [0.262s][info][class,init] Start class verification for: Test_1 [0.262s][info][class,init] End class verification for: Test_1 [0.263s][info][class,init] 282 Initializing 'Test_1' (0x000800c00800) [0.263s][info][class,init]

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Raffaello Giulietti
Hi Cheng, I'm not sure I understand your point. By class initialization I mean what's specified in the JVMS [1]. Are you concerned with initialization or with verification (which precedes initialization)? Raffaello [1]

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread David Holmes
Run with -Xlog:class+init=info to see the classes that get initialized and in what order. David On 18/03/2022 5:53 am, Raffaello Giulietti wrote: Hi again, here's code that shows that initialization doesn't happen during lookup but only upon invoking the method handle. (I'm on Java 17.)

RE: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Cheng Jin
Hi Raffaello, The code snippet I posted previously was not the original test I verified on Java 17 (which was generated via asmtools to trigger verification) Here's the pretty much the test I used: Test_1.java import java.lang.invoke.*; public class Test_1 { static MethodHandle mh;

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Raffaello Giulietti
Hi again, here's code that shows that initialization doesn't happen during lookup but only upon invoking the method handle. (I'm on Java 17.) As long as the 2nd line in main() is commented, you don't see the message "Test_2 initialized", which shows that the lookup doesn't initialize

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Raffaello Giulietti
Hi, as far as I can see, the code should not even compile, as there's a static field in Test_1 which is initialized with an expression that throws checked exceptions (findStatic(..)). In addition, it seems to me that there's nothing in your code that reveals whether Test_2 has been

Re: When to initialize the method's class for MethodHandles.Lookup.findStatic()?

2022-03-17 Thread Remi Forax
- Original Message - > From: "Cheng Jin" > To: "core-libs-dev" > Sent: Thursday, March 17, 2022 5:42:57 PM > Subject: When to initialize the method's class for > MethodHandles.Lookup.findStatic()? > Hi there, > > The document of >