Merge

Fri, 08 Nov 2013 23:49:20 +0000

author
mgerdin
date
Fri, 08 Nov 2013 23:49:20 +0000
changeset 6079
19f8a5d7600b
parent 6077
20c72bec2707
parent 6078
9d8b29a0548c
child 6080
fce21ac5968d

Merge

     1.1 --- a/src/share/vm/prims/whitebox.cpp	Fri Nov 08 07:13:57 2013 -0800
     1.2 +++ b/src/share/vm/prims/whitebox.cpp	Fri Nov 08 23:49:20 2013 +0000
     1.3 @@ -53,6 +53,8 @@
     1.4  #include "compiler/compileBroker.hpp"
     1.5  #include "runtime/compilationPolicy.hpp"
     1.6  
     1.7 +#define SIZE_T_MAX_VALUE ((size_t) -1)
     1.8 +
     1.9  bool WhiteBox::_used = false;
    1.10  
    1.11  WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
    1.12 @@ -109,6 +111,112 @@
    1.13  }
    1.14  WB_END
    1.15  
    1.16 +#ifndef PRODUCT
    1.17 +// Forward declaration
    1.18 +void TestReservedSpace_test();
    1.19 +void TestReserveMemorySpecial_test();
    1.20 +void TestVirtualSpace_test();
    1.21 +void TestMetaspaceAux_test();
    1.22 +#endif
    1.23 +
    1.24 +WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
    1.25 +#ifndef PRODUCT
    1.26 +  TestReservedSpace_test();
    1.27 +  TestReserveMemorySpecial_test();
    1.28 +  TestVirtualSpace_test();
    1.29 +  TestMetaspaceAux_test();
    1.30 +#endif
    1.31 +WB_END
    1.32 +
    1.33 +WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
    1.34 +  size_t granularity = os::vm_allocation_granularity();
    1.35 +  ReservedHeapSpace rhs(100 * granularity, granularity, false, NULL);
    1.36 +  VirtualSpace vs;
    1.37 +  vs.initialize(rhs, 50 * granularity);
    1.38 +
    1.39 +  //Check if constraints are complied
    1.40 +  if (!( UseCompressedOops && rhs.base() != NULL &&
    1.41 +         Universe::narrow_oop_base() != NULL &&
    1.42 +         Universe::narrow_oop_use_implicit_null_checks() )) {
    1.43 +    tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
    1.44 +                  "\tUseCompressedOops is %d\n"
    1.45 +                  "\trhs.base() is "PTR_FORMAT"\n"
    1.46 +                  "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n"
    1.47 +                  "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
    1.48 +                  UseCompressedOops,
    1.49 +                  rhs.base(),
    1.50 +                  Universe::narrow_oop_base(),
    1.51 +                  Universe::narrow_oop_use_implicit_null_checks());
    1.52 +    return;
    1.53 +  }
    1.54 +  tty->print_cr("Reading from no access area... ");
    1.55 +  tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
    1.56 +                *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
    1.57 +WB_END
    1.58 +
    1.59 +static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
    1.60 +                                           size_t magnitude, size_t iterations) {
    1.61 +  size_t granularity = os::vm_allocation_granularity();
    1.62 +  ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false, NULL);
    1.63 +  VirtualSpace vs;
    1.64 +  if (!vs.initialize(rhs, 0)) {
    1.65 +    tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
    1.66 +    return 3;
    1.67 +  }
    1.68 +
    1.69 +  long seed = os::random();
    1.70 +  tty->print_cr("Random seed is %ld", seed);
    1.71 +  os::init_random(seed);
    1.72 +
    1.73 +  for (size_t i = 0; i < iterations; i++) {
    1.74 +
    1.75 +    // Whether we will shrink or grow
    1.76 +    bool shrink = os::random() % 2L == 0;
    1.77 +
    1.78 +    // Get random delta to resize virtual space
    1.79 +    size_t delta = (size_t)os::random() % magnitude;
    1.80 +
    1.81 +    // If we are about to shrink virtual space below zero, then expand instead
    1.82 +    if (shrink && vs.committed_size() < delta) {
    1.83 +      shrink = false;
    1.84 +    }
    1.85 +
    1.86 +    // Resizing by delta
    1.87 +    if (shrink) {
    1.88 +      vs.shrink_by(delta);
    1.89 +    } else {
    1.90 +      // If expanding fails expand_by will silently return false
    1.91 +      vs.expand_by(delta, true);
    1.92 +    }
    1.93 +  }
    1.94 +  return 0;
    1.95 +}
    1.96 +
    1.97 +WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o,
    1.98 +        jlong reserved_space_size, jlong magnitude, jlong iterations))
    1.99 +  tty->print_cr("reservedSpaceSize="JLONG_FORMAT", magnitude="JLONG_FORMAT", "
   1.100 +                "iterations="JLONG_FORMAT"\n", reserved_space_size, magnitude,
   1.101 +                iterations);
   1.102 +  if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) {
   1.103 +    tty->print_cr("One of variables printed above is negative. Can't proceed.\n");
   1.104 +    return 1;
   1.105 +  }
   1.106 +
   1.107 +  // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is
   1.108 +  // always 8 byte. That's why we should avoid overflow in case of 32bit platform.
   1.109 +  if (sizeof(size_t) < sizeof(jlong)) {
   1.110 +    jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE;
   1.111 +    if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value
   1.112 +        || iterations > size_t_max_value) {
   1.113 +      tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n");
   1.114 +      return 2;
   1.115 +    }
   1.116 +  }
   1.117 +
   1.118 +  return wb_stress_virtual_space_resize((size_t) reserved_space_size,
   1.119 +                                        (size_t) magnitude, (size_t) iterations);
   1.120 +WB_END
   1.121 +
   1.122  #if INCLUDE_ALL_GCS
   1.123  WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
   1.124    G1CollectedHeap* g1 = G1CollectedHeap::heap();
   1.125 @@ -445,6 +553,9 @@
   1.126    {CC"getCompressedOopsMaxHeapSize", CC"()J",
   1.127        (void*)&WB_GetCompressedOopsMaxHeapSize},
   1.128    {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
   1.129 +  {CC"runMemoryUnitTests", CC"()V",                   (void*)&WB_RunMemoryUnitTests},
   1.130 +  {CC"readFromNoaccessArea",CC"()V",                  (void*)&WB_ReadFromNoaccessArea},
   1.131 +  {CC"stressVirtualSpaceResize",CC"(JJJ)I",           (void*)&WB_StressVirtualSpaceResize},
   1.132  #if INCLUDE_ALL_GCS
   1.133    {CC"g1InConcurrentMark", CC"()Z",                   (void*)&WB_G1InConcurrentMark},
   1.134    {CC"g1IsHumongous",      CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous     },
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/runtime/memory/ReadFromNoaccessArea.java	Fri Nov 08 23:49:20 2013 +0000
     2.3 @@ -0,0 +1,80 @@
     2.4 +/*
     2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @summary Test that touching noaccess area in class ReservedHeapSpace results in SIGSEGV/ACCESS_VIOLATION
    2.30 + * @library /testlibrary /testlibrary/whitebox
    2.31 + * @build ReadFromNoaccessArea
    2.32 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    2.33 + * @run main ReadFromNoaccessArea
    2.34 + */
    2.35 +
    2.36 +import com.oracle.java.testlibrary.*;
    2.37 +import sun.hotspot.WhiteBox;
    2.38 +
    2.39 +public class ReadFromNoaccessArea {
    2.40 +
    2.41 +  public static void main(String args[]) throws Exception {
    2.42 +    if (!Platform.is64bit()) {
    2.43 +      System.out.println("ReadFromNoaccessArea tests is useful only on 64bit architecture. Passing silently.");
    2.44 +      return;
    2.45 +    }
    2.46 +
    2.47 +    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    2.48 +          "-Xbootclasspath/a:.",
    2.49 +          "-XX:+UnlockDiagnosticVMOptions",
    2.50 +          "-XX:+WhiteBoxAPI",
    2.51 +          "-XX:+UseCompressedOops",
    2.52 +          "-XX:HeapBaseMinAddress=33G",
    2.53 +          DummyClassWithMainTryingToReadFromNoaccessArea.class.getName());
    2.54 +
    2.55 +    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    2.56 +    System.out.println("******* Printing stdout for analysis in case of failure *******");
    2.57 +    System.out.println(output.getStdout());
    2.58 +    System.out.println("******* Printing stderr for analysis in case of failure *******");
    2.59 +    System.out.println(output.getStderr());
    2.60 +    System.out.println("***************************************************************");
    2.61 +    if (output.getStdout() != null && output.getStdout().contains("WB_ReadFromNoaccessArea method is useless")) {
    2.62 +      // Test conditions broken. There is no protected page in ReservedHeapSpace in these circumstances. Silently passing test.
    2.63 +      return;
    2.64 +    }
    2.65 +    if (Platform.isWindows()) {
    2.66 +      output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
    2.67 +    } else if (Platform.isOSX()) {
    2.68 +      output.shouldContain("SIGBUS");
    2.69 +    } else {
    2.70 +      output.shouldContain("SIGSEGV");
    2.71 +    }
    2.72 +  }
    2.73 +
    2.74 +  public static class DummyClassWithMainTryingToReadFromNoaccessArea {
    2.75 +
    2.76 +    // This method calls whitebox method reading from noaccess area
    2.77 +    public static void main(String args[]) throws Exception {
    2.78 +      WhiteBox.getWhiteBox().readFromNoaccessArea();
    2.79 +      throw new Exception("Call of readFromNoaccessArea succeeded! This is wrong. Crash expected. Test failed.");
    2.80 +    }
    2.81 +  }
    2.82 +
    2.83 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/runtime/memory/RunUnitTestsConcurrently.java	Fri Nov 08 23:49:20 2013 +0000
     3.3 @@ -0,0 +1,74 @@
     3.4 +/*
     3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @summary Test launches unit tests inside vm concurrently
    3.30 + * @library /testlibrary /testlibrary/whitebox
    3.31 + * @build RunUnitTestsConcurrently
    3.32 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    3.33 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI RunUnitTestsConcurrently 30 15000
    3.34 + */
    3.35 +
    3.36 +import com.oracle.java.testlibrary.*;
    3.37 +import sun.hotspot.WhiteBox;
    3.38 +
    3.39 +public class RunUnitTestsConcurrently {
    3.40 +
    3.41 +  private static WhiteBox wb;
    3.42 +  private static long timeout;
    3.43 +  private static long timeStamp;
    3.44 +
    3.45 +  public static class Worker implements Runnable {
    3.46 +    @Override
    3.47 +    public void run() {
    3.48 +      while (System.currentTimeMillis() - timeStamp < timeout) {
    3.49 +        WhiteBox.getWhiteBox().runMemoryUnitTests();
    3.50 +      }
    3.51 +    }
    3.52 +  }
    3.53 +
    3.54 +  public static void main(String[] args) throws InterruptedException {
    3.55 +    if (!Platform.isDebugBuild() || !Platform.is64bit()) {
    3.56 +      return;
    3.57 +    }
    3.58 +    wb = WhiteBox.getWhiteBox();
    3.59 +    System.out.println("Starting threads");
    3.60 +
    3.61 +    int threads = Integer.valueOf(args[0]);
    3.62 +    timeout = Long.valueOf(args[1]);
    3.63 +
    3.64 +    timeStamp = System.currentTimeMillis();
    3.65 +
    3.66 +    Thread[] threadsArray = new Thread[threads];
    3.67 +    for (int i = 0; i < threads; i++) {
    3.68 +      threadsArray[i] = new Thread(new Worker());
    3.69 +      threadsArray[i].start();
    3.70 +    }
    3.71 +    for (int i = 0; i < threads; i++) {
    3.72 +      threadsArray[i].join();
    3.73 +    }
    3.74 +
    3.75 +    System.out.println("Quitting test.");
    3.76 +  }
    3.77 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/runtime/memory/StressVirtualSpaceResize.java	Fri Nov 08 23:49:20 2013 +0000
     4.3 @@ -0,0 +1,41 @@
     4.4 +/*
     4.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @summary Stress test that expands/shrinks VirtualSpace
    4.30 + * @library /testlibrary /testlibrary/whitebox
    4.31 + * @build StressVirtualSpaceResize
    4.32 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    4.33 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI StressVirtualSpaceResize
    4.34 + */
    4.35 +
    4.36 +import sun.hotspot.WhiteBox;
    4.37 +
    4.38 +public class StressVirtualSpaceResize {
    4.39 +
    4.40 +  public static void main(String args[]) throws Exception {
    4.41 +    if (WhiteBox.getWhiteBox().stressVirtualSpaceResize(1000, 0xffffL, 0xffffL) != 0)
    4.42 +      throw new RuntimeException("Whitebox method stressVirtualSpaceResize returned non zero exit code");
    4.43 +  }
    4.44 +}
     5.1 --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Fri Nov 08 07:13:57 2013 -0800
     5.2 +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Fri Nov 08 23:49:20 2013 +0000
     5.3 @@ -144,4 +144,10 @@
     5.4  
     5.5    // force Full GC
     5.6    public native void fullGC();
     5.7 +
     5.8 +  // Tests on ReservedSpace/VirtualSpace classes
     5.9 +  public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
    5.10 +  public native void runMemoryUnitTests();
    5.11 +  public native void readFromNoaccessArea();
    5.12 +
    5.13  }

mercurial