< prev index next >

test/jdk/jdk/jfr/event/runtime/TestClasses.java

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,10 +23,18 @@
  * questions.
  */
 
 package jdk.jfr.event.runtime;
 
+import java.lang.invoke.MethodType;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.reflect.Array;
+import static java.lang.invoke.MethodHandles.Lookup.ClassOption.*;
+
+import jdk.internal.misc.Unsafe;
+
 public class TestClasses {
 
     protected TestClassPrivate testClassPrivate;
     protected TestClassPrivateStatic testClassPrivateStatic;
 

@@ -74,10 +82,22 @@
 
 }
 
 class TestClass {
     static {
-        // force creation of anonymous class (for the lambda form)
+        // force creation of hidden class (for the lambda form)
         Runnable r = () -> System.out.println("Hello");
         r.run();
     }
+
+    public static void createNonFindableClasses(byte[] klassbuf) throws Throwable {
+        // Create a hidden class and an array of hidden classes.
+        Lookup lookup = MethodHandles.lookup();
+        Class<?> clh = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
+        Class<?> arrayOfHidden = Array.newInstance(clh, 10).getClass(); // HAS ISSUES?
+
+        // Create an Unsafe anonymous class and an array of unsafe anonymous classes.
+        Unsafe unsafe = Unsafe.getUnsafe();
+        Class<?> clu = unsafe.defineAnonymousClass(TestClass.class, klassbuf, new Object[0]);
+        final Class<?> arrayOfUAC = Array.newInstance(clu, 15).getClass();
+    }
 }
< prev index next >