RFR: 8349944: [JMH] sun.misc.UnsafeOps cannot access class jdk.internal.misc.Unsafe [v3]
Chen Liang
liach at openjdk.org
Thu Apr 17 05:06:56 UTC 2025
On Thu, 17 Apr 2025 03:13:05 GMT, Nicole Xu <duke at openjdk.org> wrote:
>> The UnsafeOps JMH benchmark fails with the following error:
>>
>> ```
>> java.lang.IllegalAccessError: class org.openjdk.bench.sun.misc.UnsafeOps (in unnamed module @0x520a3426) cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @0x520a3426
>> ```
>>
>> Since this micro-benchmark is created for `sun.misc.Unsafe` rather than
>> `jdk.internal.misc.Unsafe`, we change it back as before JDK-8332744.
>>
>> Note that even it will raise "proprietary API" warnings after this
>> patch, it is acceptable because the relevant APIs are bound for removal
>> for the integrity of the platform.
>
> Nicole Xu has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
>
> - Merge remote-tracking branch 'upstream/master' into JDK-8349944-add-args
>
> Change-Id: Ib60ccfc5d411f095d1c2fe6e8154a44529e84631
> - 8349944: [JMH] sun.misc.UnsafeOps cannot access class jdk.internal.misc.Unsafe
>
> The UnsafeOps JMH benchmark fails with the following error:
>
> ```
> java.lang.IllegalAccessError: class org.openjdk.bench.sun.misc.UnsafeOps (in unnamed module @0x520a3426) cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @0x520a3426
> ```
>
> Since this micro-benchmark is created for `sun.misc.Unsafe` rather than
> `jdk.internal.misc.Unsafe`, we change it back as before JDK-8332744.
>
> Note that even it will raise "proprietary API" warnings after this
> patch, it is acceptable because the relevant APIs are bound for removal
> for the integrity of the platform.
>
> Change-Id: Ia7c57c2ca09af4b2b3c6cc10ef4ae5a9f3c38a4c
> - Revert "8349944: [JMH] sun.misc.UnsafeOps cannot access class jdk.internal.misc.Unsafe"
>
> This reverts commit ebc32ae2c6e448075fedbdbb2b4879c43829c44b.
> - 8349944: [JMH] sun.misc.UnsafeOps cannot access class jdk.internal.misc.Unsafe
>
> The UnsafeOps JMH benchmark fails with the following error:
>
> ```
> java.lang.IllegalAccessError: class org.openjdk.bench.sun.misc.UnsafeOps (in unnamed module @0x520a3426) cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @0x520a3426
> ```
>
> To resolve this, we add the required `--add-opens` flag to grant access
> for the benchmark.
>
> Change-Id: I30de213daa9160ee872a4364eb332dcd1636a9ac
I have crafted a small build patch to allow benchmarks to build with all warnings not causing compilation failures. This is already the behavior for jtreg tests.
diff --git a/make/common/JavaCompilation.gmk b/make/common/JavaCompilation.gmk
index 70b3557baea..7e01e175406 100644
--- a/make/common/JavaCompilation.gmk
+++ b/make/common/JavaCompilation.gmk
@@ -271,7 +271,9 @@ define SetupJavaCompilationBody
$1_FLAGS += $$($1_JAVAC_FLAGS)
ifeq ($$(JAVA_WARNINGS_AS_ERRORS), true)
- $1_FLAGS += -Werror
+ ifeq ($$($1_MUTE_ALL_JAVA_WARNINGS), )
+ $1_FLAGS += -Werror
+ endif
endif
ifneq ($$($1_DISABLED_WARNINGS), )
diff --git a/make/test/BuildMicrobenchmark.gmk b/make/test/BuildMicrobenchmark.gmk
index 92f40472c3c..d66b6a357c5 100644
--- a/make/test/BuildMicrobenchmark.gmk
+++ b/make/test/BuildMicrobenchmark.gmk
@@ -87,6 +87,7 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \
serial preview dangling-doc-comments, \
SRC := $(MICROBENCHMARK_SRC), \
BIN := $(MICROBENCHMARK_CLASSES), \
+ MUTE_ALL_JAVA_WARNINGS := true, \
JAVAC_FLAGS := \
--add-exports java.base/jdk.internal.classfile.components=ALL-UNNAMED \
--add-exports java.base/jdk.internal.classfile.impl=ALL-UNNAMED \
Feel free to take this patch and try building and running on latest mainline.
If you use this patch, please add me as a contributor and add this patch to the build list, like
> /contributor add liach
> /label add build
And make sure other engineers agree with this approach before integrating.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23686#issuecomment-2811752056
More information about the core-libs-dev
mailing list