On Fri, 9 Dec 2022 19:39:16 GMT, Daniel D. Daugherty <dcu...@openjdk.org> wrote:

> if you asked for JVMTI_VERSION_1, could you get back JVMTI_VERSION_1_2 or 
> JVMTI_VERSION_9 or
JVMTI_VERSION_11 if the JVM in question supported each of those versions (and 
no higher)? 

Yes, but the debug agent does a version check to make sure the runtime version 
matches the compile time version.

Right now if I ask for JVMTI_VERSION_1 I will get back version 21, so it seems 
that GetEnv() always returns the version that was current when JVMTI was built, 
except of course it will fail if the requested version is newer.

It seems we update the major version with every JDK release. Here's what 
currently is produced in jvmti.h:

enum {
    JVMTI_VERSION_1   = 0x30010000,
    JVMTI_VERSION_1_0 = 0x30010000,
    JVMTI_VERSION_1_1 = 0x30010100,
    JVMTI_VERSION_1_2 = 0x30010200,
    JVMTI_VERSION_9   = 0x30090000,
    JVMTI_VERSION_11  = 0x300B0000,
    JVMTI_VERSION_19  = 0x30130000,
    JVMTI_VERSION = 0x30000000 + (21 * 0x10000) + ( 0 * 0x100) + 0  /* version: 
21.0.0 */
};

So it seems right now there is no difference in the end result between using 
JVMTI_VERSION and JVMTI_VERSION_<n>, assuming the compile and runtime versions 
match (you aren't dropping the debug agent into a different JDK build).

Now for jvmti agents that possibly could end up running in various JDK 
releases, the difference is more meaningful. They probably do not want to use 
JDK_VERSION because this could cause the agent to fail to initialize with older 
JDK releases that the agent author intends for agent to work with. Instead they 
should specify the minimum JVMTI version that they require.

Having said that it may at first seem odd that the debug agent would want to 
request JVMTI_VERSION_1, since it actually requires something newer, but the 
check to make sure that the runtime and compile time versions are the same will 
produce an error if indeed the runtime version is older than what we built 
against.  So the advantage of requesting an old version and then doing a 
runtime version check is that is that you can produce a very specific error 
message if the versioning is not right. If you rely on GetEnv to catch 
versioning issues, all you know is that you got a JNI_EVERSION error code.

-------------

PR: https://git.openjdk.org/jdk/pull/11602

Reply via email to