Skip to content

Commit b38a28b

Browse files
authored
Merge pull request #536 from perl6/jvm_beyond_java_8
[JVM] Don't warn about illegal reflective access
2 parents 43b6e8c + c88c64a commit b38a28b

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
@@ -140,11 +140,35 @@
140140
import org.perl6.nqp.sixmodel.reprs.VMIterInstance;
141141
import org.perl6.nqp.sixmodel.reprs.VMThreadInstance;
142142

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

0 commit comments

Comments
 (0)