16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Verifies the behaviour of Unsafe.defineClass 27 * @library /testlibrary 28 * @modules java.base/sun.misc 29 * java.compiler 30 * java.management 31 * @run main DefineClass 32 */ 33 34 import java.security.ProtectionDomain; 35 import java.io.InputStream; 36 import com.oracle.java.testlibrary.*; 37 import sun.misc.Unsafe; 38 import static com.oracle.java.testlibrary.Asserts.*; 39 40 public class DefineClass { 41 public static void main(String args[]) throws Exception { 42 Unsafe unsafe = Utils.getUnsafe(); 43 TestClassLoader classloader = new TestClassLoader(); 44 ProtectionDomain pd = new ProtectionDomain(null, null); 45 46 byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }"); 47 48 // Invalid class data 49 try { 50 unsafe.defineClass(null, klassbuf, 4, klassbuf.length - 4, classloader, pd); 51 throw new RuntimeException("defineClass did not throw expected ClassFormatError"); 52 } catch (ClassFormatError e) { 53 // Expected 54 } 55 56 // Negative offset 57 try { 58 unsafe.defineClass(null, klassbuf, -1, klassbuf.length, classloader, pd); | 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Verifies the behaviour of Unsafe.defineClass 27 * @library /testlibrary 28 * @modules java.base/sun.misc 29 * java.compiler 30 * java.management 31 * @run main DefineClass 32 */ 33 34 import java.security.ProtectionDomain; 35 import java.io.InputStream; 36 import jdk.test.lib.*; 37 import sun.misc.Unsafe; 38 import static jdk.test.lib.Asserts.*; 39 40 public class DefineClass { 41 public static void main(String args[]) throws Exception { 42 Unsafe unsafe = Utils.getUnsafe(); 43 TestClassLoader classloader = new TestClassLoader(); 44 ProtectionDomain pd = new ProtectionDomain(null, null); 45 46 byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }"); 47 48 // Invalid class data 49 try { 50 unsafe.defineClass(null, klassbuf, 4, klassbuf.length - 4, classloader, pd); 51 throw new RuntimeException("defineClass did not throw expected ClassFormatError"); 52 } catch (ClassFormatError e) { 53 // Expected 54 } 55 56 // Negative offset 57 try { 58 unsafe.defineClass(null, klassbuf, -1, klassbuf.length, classloader, pd); |