Skip to content

Commit 2e77b7e

Browse files
[GR-61492] Add native-image JDWP to the standard GraalVM.
PullRequest: graal/19946
2 parents 45498c8 + 22933bf commit 2e77b7e

File tree

40 files changed

+258
-337
lines changed

40 files changed

+258
-337
lines changed

compiler/mx.compiler/suite.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@
563563
org.graalvm.nativeimage.foreign,
564564
org.graalvm.nativeimage.llvm,
565565
com.oracle.svm.svm_enterprise,
566-
com.oracle.svm.jdwp.resident,
567566
com.oracle.svm_enterprise.ml_dataset,
568567
org.graalvm.nativeimage.base,
569568
org.graalvm.extraimage.builder,

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/VerifyWordFactoryUsage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
*/
2525
package jdk.graal.compiler.core.test;
2626

27+
import org.graalvm.word.WordFactory;
28+
2729
import jdk.graal.compiler.nodes.StructuredGraph;
2830
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
2931
import jdk.graal.compiler.nodes.spi.CoreProviders;
3032
import jdk.graal.compiler.phases.VerifyPhase;
3133
import jdk.graal.compiler.word.Word;
3234
import jdk.vm.ci.meta.ResolvedJavaType;
33-
import org.graalvm.word.WordFactory;
3435

3536
/**
3637
* Ensures that Graal compiler code uses factory methods in {@link Word} instead of
@@ -53,7 +54,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
5354
wordFactory.toJavaName(),
5455
graph.method().format("%H.%n(%p)"),
5556
Word.class.getName(),
56-
graph.method().format("%n(%p)"));
57+
t.targetMethod().format("%n(%p)"));
5758

5859
}
5960
}

docs/reference-manual/native-image/JDWP.md

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@ This document describes the Java Debug Wire Protocol (JDWP) debugging support fo
1313

1414
## Installation
1515

16-
The JDWP feature is not included by default as part of Native Image. To use it, you need to [build GraalVM from source](https://github.com/oracle/graal/blob/master/vm/README.md) using the following [mx](https://github.com/graalvm/mx/) commands:
16+
The JDWP feature relies on a shared library, which is loaded only when the debugger is actively used.
17+
This library must be built once before building native images with JDWP enabled.
1718
```shell
18-
mx --dynamicimports /substratevm build
19-
export JAVA_HOME=$(mx --dynamicimports /substratevm graalvm-home)
19+
native-image --macro:svmjdwp-library
2020
```
2121

22+
> Note: This is a one-time setup step. The same library will be used for all native images built with JDWP enabled.
23+
24+
> Note: This library is stored in the GraalVM installation by default.
25+
> If that directory is not writable, provide an alternative destination path with `-o <path/to/writable/directory>/libsvmjdwp`, or on Windows, use `-o <path\\to\\writable\\directory>\\svmjdwp`.
26+
2227
## Usage
2328

2429
> Note: JDWP debugging for Native Image is currently under development.
2530
26-
To include JDWP support in a native image, add the `--macro:svmjdwp` option to your `native-image` command:
31+
To include JDWP support in a native image, add the `-H:+JDWP` option to your `native-image` command:
2732

2833
```shell
29-
native-image --macro:svmjdwp ... -cp <class/path> YourApplication ...
34+
native-image -H:+UnlockExperimentalVMOptions -H:+JDWP ... -cp <class/path> YourApplication ...
3035
```
3136

3237
This command produces:
@@ -42,7 +47,7 @@ To launch the native image in debug mode, use the `-XX:JDWPOptions=` option, sim
4247
./your-application -XX:JDWPOptions=transport=dt_socket,server=y,address=8000
4348
```
4449

45-
> Note: Debugging requires the _image-name.metadata_ file generated at build time and the `svmjdwp` shared library in the same directory as the native executable.
50+
> Note: Debugging requires the _image-name.metadata_ file generated at build time and the `svmjdwp` shared library in the same directory as the native executable.
4651
4752
For a complete list of supported JDWP options on Native Image, run:
4853

@@ -72,24 +77,6 @@ Examples:
7277

7378
Note: If `lib:svmjdwp` cannot be found, the application will terminate with error code 1.
7479

75-
### Build `lib:svmjdwp`
76-
77-
Run `mx --native-images=lib:svmjdwp build` to build the library.
78-
79-
### Build a Native Executable with JDWP Support
80-
81-
Add the `--macro:svmjdwp` option to the `native-image` command:
82-
```shell
83-
mx native-image --macro:svmjdwp -cp <class/path> MainClass ...
84-
```
85-
86-
To build and include `lib:svmjdwp` as a build artifact, run:
87-
```shell
88-
mx --native-images=lib:svmjdwp native-image --macro:svmjdwp -cp <class/path> MainClass ...
89-
```
90-
91-
Both commands produce a binary, an `<image-name>.metadata` file.
92-
9380
## Goals and Constraints
9481

9582
The JDWP debugging support for Native Image aims to:

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This changelog summarizes major changes to GraalVM Native Image.
88
* (GR-52400) The build process now uses 85% of system memory in containers and CI environments. Otherwise, it tries to only use available memory. If less than 8GB of memory are available, it falls back to 85% of system memory. The reason for the selected memory limit is now also shown in the build resources section of the build output.
99
* (GR-59864) Added JVM version check to the Native Image agent. The agent will abort execution if the JVM major version does not match the version it was built with, and warn if the full JVM version is different.
1010
* (GR-59135) Verify if hosted options passed to `native-image` exist prior to starting the builder. Provide suggestions how to fix unknown options early on.
11+
* (GR-61492) The experimental JDWP option is now present in standard GraalVM builds.
1112

1213
## GraalVM for JDK 24 (Internal Version 24.2.0)
1314
* (GR-59717) Added `DuringSetupAccess.registerObjectReachabilityHandler` to allow registering a callback that is executed when an object of a specified type is marked as reachable during heap scanning.

substratevm/mx.substratevm/macro-svmjdwp.properties

Lines changed: 0 additions & 9 deletions
This file was deleted.

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,20 +1627,6 @@ def prevent_build_path_in_libgraal():
16271627
"-H:+PreserveFramePointer",
16281628
]
16291629

1630-
mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVMSvmMacro(
1631-
suite=suite,
1632-
name='SubstrateVM JDWP Debugger Resident',
1633-
short_name='svmjdwp',
1634-
dir_name="svmjdwp",
1635-
license_files=[],
1636-
third_party_license_files=[],
1637-
dependencies=['SubstrateVM'],
1638-
builder_jar_distributions=['substratevm:SVM_JDWP_COMMON', 'substratevm:SVM_JDWP_RESIDENT'],
1639-
support_distributions=['substratevm:SVM_JDWP_RESIDENT_SUPPORT'],
1640-
stability="experimental",
1641-
jlink=False,
1642-
))
1643-
16441630
libsvmjdwp_lib_config = mx_sdk_vm.LibraryConfig(
16451631
destination="<lib:svmjdwp>",
16461632
jvm_library=True,
@@ -1655,7 +1641,7 @@ def prevent_build_path_in_libgraal():
16551641
libsvmjdwp = mx_sdk_vm.GraalVmJreComponent(
16561642
suite=suite,
16571643
name='SubstrateVM JDWP Debugger',
1658-
short_name='svmjdwpserver',
1644+
short_name='svmjdwp',
16591645
dir_name="svm",
16601646
license_files=[],
16611647
third_party_license_files=[],

substratevm/mx.substratevm/suite.py

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@
686686
"requires" : [
687687
"jdk.jfr",
688688
"jdk.management",
689+
"java.instrument",
689690
],
690691
"requiresConcealed" : {
691692
"java.base" : [
@@ -710,9 +711,6 @@
710711
"sun.util.locale",
711712
"sun.invoke.util",
712713
],
713-
"java.instrument":[
714-
"java.lang.instrument"
715-
],
716714
"java.management": [
717715
"com.sun.jmx.mbeanserver", # Needed for javadoc links (MXBeanIntrospector,DefaultMXBeanMappingFactory, MXBeanProxy)
718716
"sun.management", # Needed for javadoc links (MappedMXBeanType)
@@ -1575,7 +1573,8 @@
15751573
"subDir": "src",
15761574
"sourceDirs": ["src"],
15771575
"dependencies": [
1578-
"substratevm:SVM"
1576+
"com.oracle.svm.core",
1577+
"com.oracle.graal.pointsto",
15791578
],
15801579
"requiresConcealed" : {
15811580
"jdk.internal.vm.ci" : [
@@ -1593,6 +1592,8 @@
15931592
"sourceDirs": ["src"],
15941593
"dependencies": [
15951594
"com.oracle.svm.interpreter.metadata",
1595+
"com.oracle.svm.core.graal.aarch64",
1596+
"com.oracle.svm.graal",
15961597
],
15971598
"requires" : [
15981599
"java.base"
@@ -1621,7 +1622,7 @@
16211622
"subDir": "src",
16221623
"sourceDirs": ["src"],
16231624
"dependencies": [
1624-
"substratevm:SVM",
1625+
"com.oracle.svm.core",
16251626
],
16261627
"requiresConcealed" : {
16271628
"jdk.internal.vm.ci" : [
@@ -1718,6 +1719,7 @@
17181719
"com.oracle.svm.core.posix",
17191720
"com.oracle.svm.core.windows",
17201721
"com.oracle.svm.core.genscavenge",
1722+
"com.oracle.svm.jdwp.resident",
17211723
],
17221724
"distDependencies": [
17231725
"sdk:NATIVEIMAGE",
@@ -1747,12 +1749,15 @@
17471749
org.graalvm.extraimage.librarysupport,
17481750
com.oracle.svm.extraimage_enterprise,
17491751
org.graalvm.nativeimage.foreign,
1750-
com.oracle.svm.jdwp.common,
17511752
com.oracle.svm.jdwp.server,
1752-
com.oracle.svm.jdwp.resident,
17531753
org.graalvm.truffle.runtime.svm,
17541754
com.oracle.truffle.enterprise.svm""",
17551755
"com.oracle.svm.hosted.c.libc to com.oracle.graal.sandbox",
1756+
"com.oracle.svm.jdwp.bridge to com.oracle.svm.jdwp.server",
1757+
"com.oracle.svm.jdwp.bridge.nativebridge to com.oracle.svm.jdwp.server",
1758+
"com.oracle.svm.jdwp.bridge.jniutils to com.oracle.svm.jdwp.server",
1759+
"com.oracle.svm.interpreter.metadata to com.oracle.svm.jdwp.server",
1760+
"com.oracle.svm.interpreter.metadata.serialization to com.oracle.svm.jdwp.server",
17561761
],
17571762
"opens" : [
17581763
"com.oracle.svm.core to jdk.graal.compiler",
@@ -1762,7 +1767,6 @@
17621767
"com.oracle.svm.hosted.fieldfolding to jdk.graal.compiler",
17631768
"com.oracle.svm.hosted.phases to jdk.graal.compiler",
17641769
"com.oracle.svm.hosted.reflect to jdk.graal.compiler",
1765-
"com.oracle.svm.core.thread to com.oracle.svm.jdwp.resident",
17661770
],
17671771
"requires": [
17681772
"java.management",
@@ -2229,7 +2233,7 @@
22292233
"org.graalvm.collections",
22302234
],
22312235
"exports" : [
2232-
"com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,com.oracle.svm.jdwp.resident,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
2236+
"com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
22332237
"com.oracle.svm.common.meta to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,org.graalvm.extraimage.builder,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
22342238
"com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
22352239
],
@@ -2549,68 +2553,18 @@
25492553
},
25502554
},
25512555

2552-
"SVM_JDWP_COMMON": {
2553-
"subDir": "src",
2554-
"dependencies": [
2555-
"com.oracle.svm.interpreter.metadata",
2556-
"com.oracle.svm.jdwp.bridge",
2557-
],
2558-
"distDependencies": [
2559-
"SVM",
2560-
],
2561-
"moduleInfo" : {
2562-
"name" : "com.oracle.svm.jdwp.common",
2563-
"exports" : [
2564-
"com.oracle.svm.jdwp.bridge to com.oracle.svm.jdwp.server,com.oracle.svm.jdwp.resident",
2565-
"com.oracle.svm.jdwp.bridge.nativebridge to com.oracle.svm.jdwp.server,com.oracle.svm.jdwp.resident",
2566-
"com.oracle.svm.jdwp.bridge.jniutils to com.oracle.svm.jdwp.server,com.oracle.svm.jdwp.resident",
2567-
"com.oracle.svm.interpreter.metadata to com.oracle.svm.jdwp.server,com.oracle.svm.jdwp.resident",
2568-
"com.oracle.svm.interpreter.metadata.serialization to com.oracle.svm.jdwp.server,com.oracle.svm.jdwp.resident",
2569-
],
2570-
"requires" : [
2571-
"org.graalvm.collections",
2572-
],
2573-
}
2574-
},
2575-
2576-
"SVM_JDWP_RESIDENT": {
2577-
"subDir": "src",
2578-
"dependencies": [
2579-
"com.oracle.svm.jdwp.resident",
2580-
],
2581-
"distDependencies": [
2582-
"SVM_JDWP_COMMON",
2583-
"sdk:COLLECTIONS",
2584-
"compiler:GRAAL",
2585-
],
2586-
"moduleInfo" : {
2587-
"name" : "com.oracle.svm.jdwp.resident",
2588-
"exports": [
2589-
"com.oracle.svm.interpreter,com.oracle.svm.jdwp.resident to org.graalvm.nativeimage.builder",
2590-
],
2591-
}
2592-
},
2593-
2594-
"SVM_JDWP_RESIDENT_SUPPORT" : {
2595-
"native" : True,
2596-
"description" : "JDWP debugging support",
2597-
"layout" : {
2598-
"native-image.properties" : "file:mx.substratevm/macro-svmjdwp.properties",
2599-
},
2600-
},
2601-
26022556
"SVM_JDWP_SERVER": {
26032557
"subDir": "src",
26042558
"dependencies": [
26052559
"com.oracle.svm.jdwp.server",
26062560
],
26072561
"distDependencies": [
26082562
"substratevm:SVM",
2609-
"SVM_JDWP_COMMON",
26102563
],
26112564
"moduleInfo" : {
26122565
"name" : "com.oracle.svm.jdwp.server",
2613-
}
2566+
},
2567+
"maven" : False,
26142568
},
26152569

26162570
},

substratevm/src/com.oracle.svm.interpreter.metadata/src/com/oracle/svm/interpreter/metadata/InterpreterResolvedJavaMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333

3434
import org.graalvm.nativeimage.Platform;
3535
import org.graalvm.nativeimage.Platforms;
36-
import org.graalvm.word.WordFactory;
3736

3837
import com.oracle.svm.core.FunctionPointerHolder;
3938
import com.oracle.svm.core.meta.MethodPointer;
4039
import com.oracle.svm.core.util.VMError;
4140
import com.oracle.svm.interpreter.metadata.serialization.VisibleForSerialization;
4241

42+
import jdk.graal.compiler.word.Word;
4343
import jdk.vm.ci.meta.Constant;
4444
import jdk.vm.ci.meta.ExceptionHandler;
4545
import jdk.vm.ci.meta.LineNumberTable;
@@ -387,7 +387,7 @@ public boolean hasNativeEntryPoint() {
387387

388388
public MethodPointer getNativeEntryPoint() {
389389
if (nativeEntryPoint == null) {
390-
return WordFactory.nullPointer();
390+
return Word.nullPointer();
391391
}
392392
return (MethodPointer) nativeEntryPoint.getReferent().functionPointer;
393393
}

substratevm/src/com.oracle.svm.interpreter.metadata/src/com/oracle/svm/interpreter/metadata/serialization/Serializers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131
import java.util.function.IntFunction;
3232
import java.util.function.ToLongFunction;
3333

34-
import com.oracle.svm.interpreter.metadata.ReferenceConstant;
3534
import org.graalvm.nativeimage.Platform;
3635
import org.graalvm.nativeimage.Platforms;
3736
import org.graalvm.word.Pointer;
38-
import org.graalvm.word.WordFactory;
3937

4038
import com.oracle.svm.core.FunctionPointerHolder;
4139
import com.oracle.svm.core.snippets.KnownIntrinsics;
@@ -47,7 +45,9 @@
4745
import com.oracle.svm.interpreter.metadata.InterpreterResolvedObjectType;
4846
import com.oracle.svm.interpreter.metadata.InterpreterResolvedPrimitiveType;
4947
import com.oracle.svm.interpreter.metadata.InterpreterUnresolvedSignature;
48+
import com.oracle.svm.interpreter.metadata.ReferenceConstant;
5049

50+
import jdk.graal.compiler.word.Word;
5151
import jdk.vm.ci.meta.ExceptionHandler;
5252
import jdk.vm.ci.meta.JavaConstant;
5353
import jdk.vm.ci.meta.JavaKind;
@@ -282,7 +282,7 @@ static <T> ValueSerializer<T> asReferenceConstant() {
282282
return ReferenceConstant.nullReference();
283283
}
284284
Pointer heapBase = KnownIntrinsics.heapBase();
285-
Object ref = heapBase.add(WordFactory.unsigned(nativeHeapAddress)).toObject();
285+
Object ref = heapBase.add(Word.unsigned(nativeHeapAddress)).toObject();
286286
return ReferenceConstant.createFromNonNullReference(ref);
287287
} else {
288288
// The reference could have been serialized despite not being on the native image heap.

0 commit comments

Comments
 (0)