Skip to content

Commit c88c64a

Browse files
committed
[JVM] Don't warn about illegal reflective access
... on Java 9 and newer.
1 parent 0adfd6a commit c88c64a

File tree

1 file changed

+24
-0
lines changed
  • src/vm/jvm/runtime/org/perl6/nqp/runtime

1 file changed

+24
-0
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,35 @@
139139
import org.perl6.nqp.sixmodel.reprs.VMIterInstance;
140140
import org.perl6.nqp.sixmodel.reprs.VMThreadInstance;
141141

142+
import sun.misc.Unsafe;
143+
142144
/**
143145
* Contains complex operations that are more involved than the simple ops that the
144146
* JVM makes available.
145147
*/
146148
public final class Ops {
149+
/**
150+
* Temporary workaround to avoid warnings about 'illegal reflective access'
151+
* (taken from https://stackoverflow.com/a/46458447).
152+
* Please note that this is needed for Rakudo, too.
153+
* Once something else (e.g. VarHandle) is used instead
154+
* of sun.misc.Unsafe this workaround can be removed.
155+
*/
156+
public static void disableWarning() {
157+
try {
158+
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
159+
theUnsafe.setAccessible(true);
160+
Unsafe u = (Unsafe)theUnsafe.get(null);
161+
162+
Class cls = Class.forName("jdk.internal.module.IllegalAccessLogger");
163+
Field logger = cls.getDeclaredField("logger");
164+
u.putObjectVolatile(cls, u.staticFieldOffset(logger), null);
165+
}
166+
catch (Exception e) {
167+
// ignore (that's the raison d'être for this method)
168+
}
169+
}
170+
147171
/* I/O opcodes */
148172
public static String print(String v, ThreadContext tc) {
149173
tc.gc.out.print(v);

0 commit comments

Comments
 (0)