< prev index next >

test/hotspot/jtreg/runtime/Unsafe/RangeCheck.java

Print this page




  42         if (!Platform.isDebugBuild()) {
  43             System.out.println("Testing assert which requires a debug build. Passing silently.");
  44             return;
  45         }
  46 
  47         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  48                 true,
  49                 "-Xmx128m",
  50                 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
  51                 "-XX:-CreateCoredumpOnCrash",
  52                 "-XX:-InlineUnsafeOps", // The compiler intrinsics doesn't have the assert
  53                 DummyClassWithMainRangeCheck.class.getName());
  54 
  55         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  56         output.shouldMatch("assert\\(byte_offset < p_size\\) failed: Unsafe access: offset \\d+ > object's size \\d+");
  57     }
  58 
  59     public static class DummyClassWithMainRangeCheck {
  60         public static void main(String args[]) throws Exception {
  61             Unsafe unsafe = Unsafe.getUnsafe();
  62             unsafe.getObject(new DummyClassWithMainRangeCheck(), Short.MAX_VALUE);
  63         }
  64     }
  65 }


  42         if (!Platform.isDebugBuild()) {
  43             System.out.println("Testing assert which requires a debug build. Passing silently.");
  44             return;
  45         }
  46 
  47         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  48                 true,
  49                 "-Xmx128m",
  50                 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
  51                 "-XX:-CreateCoredumpOnCrash",
  52                 "-XX:-InlineUnsafeOps", // The compiler intrinsics doesn't have the assert
  53                 DummyClassWithMainRangeCheck.class.getName());
  54 
  55         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  56         output.shouldMatch("assert\\(byte_offset < p_size\\) failed: Unsafe access: offset \\d+ > object's size \\d+");
  57     }
  58 
  59     public static class DummyClassWithMainRangeCheck {
  60         public static void main(String args[]) throws Exception {
  61             Unsafe unsafe = Unsafe.getUnsafe();
  62             unsafe.getReference(new DummyClassWithMainRangeCheck(), Short.MAX_VALUE);
  63         }
  64     }
  65 }
< prev index next >