Skip to content

Commit 59a07aa

Browse files
[GR-45171] Basic JVMTI infrastructure.
PullRequest: graal/18467
2 parents 84daad0 + f5101cb commit 59a07aa

File tree

76 files changed

+6383
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+6383
-9
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,17 @@ public static void updateMaxJavaStackTraceDepth(EconomicMap<OptionKey<?>, Object
633633
@Option(help = "JNI functions will return more specific error codes.", type = OptionType.User)//
634634
public static final HostedOptionKey<Boolean> JNIEnhancedErrorCodes = new HostedOptionKey<>(false);
635635

636+
@Option(help = "Enable JVM Tool Interface (JVMTI) support.", type = OptionType.User)//
637+
public static final HostedOptionKey<Boolean> JVMTI = new HostedOptionKey<>(false);
638+
639+
@Option(help = "Loads the specified native agent library. " +
640+
"After the library name, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
641+
public static final RuntimeOptionKey<String> JVMTIAgentLib = new RuntimeOptionKey<>(null);
642+
643+
@Option(help = "Loads the specified native agent library specified by the absolute path name. " +
644+
"After the library path, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
645+
public static final RuntimeOptionKey<String> JVMTIAgentPath = new RuntimeOptionKey<>(null);
646+
636647
@Option(help = "Alignment of AOT and JIT compiled code in bytes.")//
637648
public static final HostedOptionKey<Integer> CodeAlignment = new HostedOptionKey<>(16);
638649

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibraries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected static PointerBase findSymbol(Collection<PlatformNativeLibrarySupport.
6868

6969
/** Returns the directory containing the native image, or {@code null}. */
7070
@NeverInline("Reads the return address.")
71-
private static String getImageDirectory() {
71+
public static String getImageDirectory() {
7272
/*
7373
* While one might expect code for shared libraries to work for executables as well, this is
7474
* not necessarily the case. For example, `dladdr` on Linux returns `argv[0]` for

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/access/JNIAccessibleMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ boolean isPublic() {
157157
return Modifier.isPublic(modifiers);
158158
}
159159

160+
public boolean isNative() {
161+
return Modifier.isNative(modifiers);
162+
}
163+
160164
boolean isStatic() {
161165
return Modifier.isStatic(modifiers);
162166
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIInvocationInterface.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.graalvm.word.UnsignedWord;
4040
import org.graalvm.word.WordFactory;
4141

42+
import com.oracle.svm.core.SubstrateOptions;
4243
import com.oracle.svm.core.Uninterruptible;
4344
import com.oracle.svm.core.UnmanagedMemoryUtil;
4445
import com.oracle.svm.core.c.CGlobalData;
@@ -68,6 +69,9 @@
6869
import com.oracle.svm.core.jni.headers.JNIJavaVMOption;
6970
import com.oracle.svm.core.jni.headers.JNIJavaVMPointer;
7071
import com.oracle.svm.core.jni.headers.JNIVersion;
72+
import com.oracle.svm.core.jvmti.JvmtiEnvs;
73+
import com.oracle.svm.core.jvmti.headers.JvmtiExternalEnv;
74+
import com.oracle.svm.core.jvmti.headers.JvmtiVersion;
7175
import com.oracle.svm.core.log.FunctionPointerLogHandler;
7276
import com.oracle.svm.core.memory.UntrackedNullableNativeMemory;
7377
import com.oracle.svm.core.monitor.MonitorInflationCause;
@@ -291,8 +295,17 @@ static int DestroyJavaVM(JNIJavaVM vm) {
291295
@CEntryPointOptions(prologue = JNIGetEnvPrologue.class)
292296
@SuppressWarnings("unused")
293297
static int GetEnv(JNIJavaVM vm, WordPointer env, int version) {
294-
env.write(JNIThreadLocalEnvironment.getAddress());
295-
return JNIErrors.JNI_OK();
298+
if (SubstrateOptions.JVMTI.getValue() && JvmtiVersion.isSupported(version)) {
299+
JvmtiExternalEnv jvmtiEnv = JvmtiEnvs.singleton().create();
300+
env.write(jvmtiEnv);
301+
return JNIErrors.JNI_OK();
302+
} else if (JNIVersion.isSupported(version, false)) {
303+
env.write(JNIThreadLocalEnvironment.getAddress());
304+
return JNIErrors.JNI_OK();
305+
} else {
306+
env.write(WordFactory.nullPointer());
307+
return JNIErrors.JNI_EVERSION();
308+
}
296309
}
297310

298311
// Checkstyle: resume
@@ -308,14 +321,10 @@ static class Support {
308321

309322
static class JNIGetEnvPrologue implements CEntryPointOptions.Prologue {
310323
@Uninterruptible(reason = "prologue")
311-
static int enter(JNIJavaVM vm, WordPointer env, int version) {
324+
static int enter(JNIJavaVM vm, WordPointer env) {
312325
if (vm.isNull() || env.isNull()) {
313326
return JNIErrors.JNI_ERR();
314327
}
315-
if (!JNIVersion.isSupported(version, false)) {
316-
env.write(WordFactory.nullPointer());
317-
return JNIErrors.JNI_EVERSION();
318-
}
319328
if (!CEntryPointActions.isCurrentThreadAttachedTo(vm.getFunctions().getIsolate())) {
320329
env.write(WordFactory.nullPointer());
321330
return JNIErrors.JNI_EDETACHED();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jni.headers;
26+
27+
import org.graalvm.nativeimage.c.CContext;
28+
import org.graalvm.nativeimage.c.struct.CPointerTo;
29+
import org.graalvm.word.PointerBase;
30+
31+
@CContext(JNIHeaderDirectives.class)
32+
@CPointerTo(JNIFieldId.class)
33+
public interface JNIFieldIdPointer extends PointerBase {
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jni.headers;
26+
27+
import org.graalvm.nativeimage.c.CContext;
28+
import org.graalvm.nativeimage.c.struct.CPointerTo;
29+
import org.graalvm.word.PointerBase;
30+
31+
@CContext(JNIHeaderDirectives.class)
32+
@CPointerTo(JNIFieldIdPointer.class)
33+
public interface JNIFieldIdPointerPointer extends PointerBase {
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jni.headers;
26+
27+
import org.graalvm.nativeimage.c.CContext;
28+
import org.graalvm.nativeimage.c.struct.CPointerTo;
29+
import org.graalvm.word.PointerBase;
30+
31+
@CContext(JNIHeaderDirectives.class)
32+
@CPointerTo(JNIMethodId.class)
33+
public interface JNIMethodIdPointer extends PointerBase {
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jni.headers;
26+
27+
import org.graalvm.nativeimage.c.CContext;
28+
import org.graalvm.nativeimage.c.struct.CPointerTo;
29+
import org.graalvm.word.PointerBase;
30+
31+
@CContext(JNIHeaderDirectives.class)
32+
@CPointerTo(JNIMethodIdPointer.class)
33+
public interface JNIMethodIdPointerPointer extends PointerBase {
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jni.headers;
26+
27+
import org.graalvm.nativeimage.c.CContext;
28+
import org.graalvm.nativeimage.c.struct.CPointerTo;
29+
import org.graalvm.word.PointerBase;
30+
31+
@CContext(JNIHeaderDirectives.class)
32+
@CPointerTo(JNINativeInterface.class)
33+
public interface JNINativeInterfacePointer extends PointerBase {
34+
}

0 commit comments

Comments
 (0)