Merge
authorsla
Thu, 06 Nov 2014 19:59:32 +0000
changeset 27480 51e6396f8a98
parent 27479 389ec536ece9 (current diff)
parent 27456 854b988388f3 (diff)
child 27481 e5814e373085
child 27609 d24e9561d2a4
Merge
hotspot/src/share/vm/oops/method.cpp
hotspot/src/share/vm/prims/whitebox.cpp
hotspot/test/TEST.groups
hotspot/test/serviceability/threads/TestFalseDeadLock.java
--- a/hotspot/src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -36,8 +36,7 @@
 #include <dlfcn.h>
 #include <link.h>
 
-extern "C" static int PICL_get_l1_data_cache_line_size_helper(picl_nodehdl_t nodeh, void *result);
-extern "C" static int PICL_get_l2_cache_line_size_helper(picl_nodehdl_t nodeh, void *result);
+extern "C" static int PICL_visit_cpu_helper(picl_nodehdl_t nodeh, void *result);
 
 // Functions from the library we need (signatures should match those in picl.h)
 extern "C" {
@@ -130,60 +129,74 @@
     bool is_inconsistent()  { return _state == INCONSISTENT; }
     void set_inconsistent() { _state = INCONSISTENT;         }
 
-    static int visit(picl_nodehdl_t nodeh, const char* name, void *arg) {
-      UniqueValueVisitor *state = static_cast<UniqueValueVisitor*>(arg);
-      PICL* picl = state->_picl;
-      assert(!state->is_inconsistent(), "Precondition");
+    void visit(picl_nodehdl_t nodeh, const char* name) {
+      assert(!is_inconsistent(), "Precondition");
       int curr;
-      if (picl->get_int_property(nodeh, name, &curr) == PICL_SUCCESS) {
-        if (!state->is_assigned()) { // first iteration
-          state->set_value(curr);
-        } else if (curr != state->value()) { // following iterations
-          state->set_inconsistent();
+      if (_picl->get_int_property(nodeh, name, &curr) == PICL_SUCCESS) {
+        if (!is_assigned()) { // first iteration
+          set_value(curr);
+        } else if (curr != value()) { // following iterations
+          set_inconsistent();
         }
       }
-      if (state->is_inconsistent()) {
+    }
+  };
+
+  class CPUVisitor {
+    UniqueValueVisitor _l1_visitor;
+    UniqueValueVisitor _l2_visitor;
+    int _limit; // number of times visit() can be run
+  public:
+    CPUVisitor(PICL *picl, int limit) : _l1_visitor(picl), _l2_visitor(picl), _limit(limit) {}
+    static int visit(picl_nodehdl_t nodeh, void *arg) {
+      CPUVisitor *cpu_visitor = static_cast<CPUVisitor*>(arg);
+      UniqueValueVisitor* l1_visitor = cpu_visitor->l1_visitor();
+      UniqueValueVisitor* l2_visitor = cpu_visitor->l2_visitor();
+      if (!l1_visitor->is_inconsistent()) {
+        l1_visitor->visit(nodeh, "l1-dcache-line-size");
+      }
+      if (!l2_visitor->is_inconsistent()) {
+        l2_visitor->visit(nodeh, "l2-cache-line-size");
+      }
+
+      if (l1_visitor->is_inconsistent() && l2_visitor->is_inconsistent()) {
+        return PICL_WALK_TERMINATE;
+      }
+      cpu_visitor->_limit--;
+      if (cpu_visitor->_limit <= 0) {
         return PICL_WALK_TERMINATE;
       }
       return PICL_WALK_CONTINUE;
     }
+    UniqueValueVisitor* l1_visitor() { return &_l1_visitor; }
+    UniqueValueVisitor* l2_visitor() { return &_l2_visitor; }
   };
-
   int _L1_data_cache_line_size;
   int _L2_cache_line_size;
 public:
-  static int get_l1_data_cache_line_size(picl_nodehdl_t nodeh, void *state) {
-    return UniqueValueVisitor::visit(nodeh, "l1-dcache-line-size", state);
-  }
-  static int get_l2_cache_line_size(picl_nodehdl_t nodeh, void *state) {
-    return UniqueValueVisitor::visit(nodeh, "l2-cache-line-size", state);
+  static int visit_cpu(picl_nodehdl_t nodeh, void *state) {
+    return CPUVisitor::visit(nodeh, state);
   }
 
-  PICL() : _L1_data_cache_line_size(0), _L2_cache_line_size(0), _dl_handle(NULL) {
+  PICL(bool is_fujitsu) : _L1_data_cache_line_size(0), _L2_cache_line_size(0), _dl_handle(NULL) {
     if (!open_library()) {
       return;
     }
     if (_picl_initialize() == PICL_SUCCESS) {
       picl_nodehdl_t rooth;
       if (_picl_get_root(&rooth) == PICL_SUCCESS) {
-        UniqueValueVisitor L1_state(this);
-        // Visit all "cpu" class instances
-        _picl_walk_tree_by_class(rooth, "cpu", &L1_state, PICL_get_l1_data_cache_line_size_helper);
-        if (L1_state.is_initial()) { // Still initial, iteration found no values
-          // Try walk all "core" class instances, it might be a Fujitsu machine
-          _picl_walk_tree_by_class(rooth, "core", &L1_state, PICL_get_l1_data_cache_line_size_helper);
+        const char* cpu_class = "cpu";
+        // If it's a Fujitsu machine, it's a "core"
+        if (is_fujitsu) {
+          cpu_class = "core";
         }
-        if (L1_state.is_assigned()) { // Is there a value?
-          _L1_data_cache_line_size = L1_state.value();
+        CPUVisitor cpu_visitor(this, os::processor_count());
+        _picl_walk_tree_by_class(rooth, cpu_class, &cpu_visitor, PICL_visit_cpu_helper);
+        if (cpu_visitor.l1_visitor()->is_assigned()) { // Is there a value?
+          _L1_data_cache_line_size = cpu_visitor.l1_visitor()->value();
         }
-
-        UniqueValueVisitor L2_state(this);
-        _picl_walk_tree_by_class(rooth, "cpu", &L2_state, PICL_get_l2_cache_line_size_helper);
-        if (L2_state.is_initial()) {
-          _picl_walk_tree_by_class(rooth, "core", &L2_state, PICL_get_l2_cache_line_size_helper);
-        }
-        if (L2_state.is_assigned()) {
-          _L2_cache_line_size = L2_state.value();
+        if (cpu_visitor.l2_visitor()->is_assigned()) {
+          _L2_cache_line_size = cpu_visitor.l2_visitor()->value();
         }
       }
       _picl_shutdown();
@@ -195,11 +208,9 @@
   unsigned int L2_cache_line_size() const      { return _L2_cache_line_size;      }
 };
 
-extern "C" static int PICL_get_l1_data_cache_line_size_helper(picl_nodehdl_t nodeh, void *result) {
-  return PICL::get_l1_data_cache_line_size(nodeh, result);
-}
-extern "C" static int PICL_get_l2_cache_line_size_helper(picl_nodehdl_t nodeh, void *result) {
-  return PICL::get_l2_cache_line_size(nodeh, result);
+
+extern "C" static int PICL_visit_cpu_helper(picl_nodehdl_t nodeh, void *result) {
+  return PICL::visit_cpu(nodeh, result);
 }
 
 template<typename FuncType>
@@ -418,7 +429,7 @@
   }
 
   // Figure out cache line sizes using PICL
-  PICL picl;
+  PICL picl((features & sparc64_family_m) != 0);
   _L1_data_cache_line_size = picl.L1_data_cache_line_size();
   _L2_cache_line_size      = picl.L2_cache_line_size();
 
--- a/hotspot/src/share/vm/classfile/vmSymbols.hpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp	Thu Nov 06 19:59:32 2014 +0000
@@ -455,6 +455,7 @@
   template(object_void_signature,                     "(Ljava/lang/Object;)V")                    \
   template(object_int_signature,                      "(Ljava/lang/Object;)I")                    \
   template(object_boolean_signature,                  "(Ljava/lang/Object;)Z")                    \
+  template(object_object_signature,                   "(Ljava/lang/Object;)Ljava/lang/Object;")   \
   template(string_void_signature,                     "(Ljava/lang/String;)V")                    \
   template(string_int_signature,                      "(Ljava/lang/String;)I")                    \
   template(throwable_void_signature,                  "(Ljava/lang/Throwable;)V")                 \
@@ -746,6 +747,8 @@
    do_name(     isPrimitive_name,                                "isPrimitive")                                         \
   do_intrinsic(_getSuperclass,            java_lang_Class,        getSuperclass_name, void_class_signature,      F_RN)  \
    do_name(     getSuperclass_name,                              "getSuperclass")                                       \
+  do_intrinsic(_Class_cast,               java_lang_Class,        Class_cast_name, object_object_signature,      F_R)   \
+   do_name(     Class_cast_name,                                 "cast")                                                \
                                                                                                                         \
   do_intrinsic(_getClassAccessFlags,      sun_reflect_Reflection, getClassAccessFlags_name, class_int_signature, F_SN)  \
    do_name(     getClassAccessFlags_name,                        "getClassAccessFlags")                                 \
--- a/hotspot/src/share/vm/oops/method.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/oops/method.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -1318,6 +1318,10 @@
   vmIntrinsics::ID id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags);
   if (id != vmIntrinsics::_none) {
     set_intrinsic_id(id);
+    if (id == vmIntrinsics::_Class_cast) {
+      // Even if the intrinsic is rejected, we want to inline this simple method.
+      set_force_inline(true);
+    }
     return;
   }
 
--- a/hotspot/src/share/vm/opto/lcm.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/opto/lcm.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -464,9 +464,7 @@
         iop == Op_CreateEx ||   // Create-exception must start block
         iop == Op_CheckCastPP
         ) {
-      // select the node n
-      // remove n from worklist and retain the order of remaining nodes
-      worklist.remove((uint)i);
+      worklist.map(i,worklist.pop());
       return n;
     }
 
@@ -552,9 +550,7 @@
   assert(idx >= 0, "index should be set");
   Node *n = worklist[(uint)idx];      // Get the winner
 
-  // select the node n
-  // remove n from worklist and retain the order of remaining nodes
-  worklist.remove((uint)idx);
+  worklist.map((uint)idx, worklist.pop());     // Compress worklist
   return n;
 }
 
--- a/hotspot/src/share/vm/opto/library_call.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -268,6 +268,7 @@
   bool inline_fp_conversions(vmIntrinsics::ID id);
   bool inline_number_methods(vmIntrinsics::ID id);
   bool inline_reference_get();
+  bool inline_Class_cast();
   bool inline_aescrypt_Block(vmIntrinsics::ID id);
   bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id);
   Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting);
@@ -869,6 +870,8 @@
 
   case vmIntrinsics::_Reference_get:            return inline_reference_get();
 
+  case vmIntrinsics::_Class_cast:               return inline_Class_cast();
+
   case vmIntrinsics::_aescrypt_encryptBlock:
   case vmIntrinsics::_aescrypt_decryptBlock:    return inline_aescrypt_Block(intrinsic_id());
 
@@ -3546,6 +3549,89 @@
   return true;
 }
 
+//-------------------------inline_Class_cast-------------------
+bool LibraryCallKit::inline_Class_cast() {
+  Node* mirror = argument(0); // Class
+  Node* obj    = argument(1);
+  const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
+  if (mirror_con == NULL) {
+    return false;  // dead path (mirror->is_top()).
+  }
+  if (obj == NULL || obj->is_top()) {
+    return false;  // dead path
+  }
+  const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr();
+
+  // First, see if Class.cast() can be folded statically.
+  // java_mirror_type() returns non-null for compile-time Class constants.
+  ciType* tm = mirror_con->java_mirror_type();
+  if (tm != NULL && tm->is_klass() &&
+      tp != NULL && tp->klass() != NULL) {
+    if (!tp->klass()->is_loaded()) {
+      // Don't use intrinsic when class is not loaded.
+      return false;
+    } else {
+      int static_res = C->static_subtype_check(tm->as_klass(), tp->klass());
+      if (static_res == Compile::SSC_always_true) {
+        // isInstance() is true - fold the code.
+        set_result(obj);
+        return true;
+      } else if (static_res == Compile::SSC_always_false) {
+        // Don't use intrinsic, have to throw ClassCastException.
+        // If the reference is null, the non-intrinsic bytecode will
+        // be optimized appropriately.
+        return false;
+      }
+    }
+  }
+
+  // Bailout intrinsic and do normal inlining if exception path is frequent.
+  if (too_many_traps(Deoptimization::Reason_intrinsic)) {
+    return false;
+  }
+
+  // Generate dynamic checks.
+  // Class.cast() is java implementation of _checkcast bytecode.
+  // Do checkcast (Parse::do_checkcast()) optimizations here.
+
+  mirror = null_check(mirror);
+  // If mirror is dead, only null-path is taken.
+  if (stopped()) {
+    return true;
+  }
+
+  // Not-subtype or the mirror's klass ptr is NULL (in case it is a primitive).
+  enum { _bad_type_path = 1, _prim_path = 2, PATH_LIMIT };
+  RegionNode* region = new RegionNode(PATH_LIMIT);
+  record_for_igvn(region);
+
+  // Now load the mirror's klass metaobject, and null-check it.
+  // If kls is null, we have a primitive mirror and
+  // nothing is an instance of a primitive type.
+  Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path);
+
+  Node* res = top();
+  if (!stopped()) {
+    Node* bad_type_ctrl = top();
+    // Do checkcast optimizations.
+    res = gen_checkcast(obj, kls, &bad_type_ctrl);
+    region->init_req(_bad_type_path, bad_type_ctrl);
+  }
+  if (region->in(_prim_path) != top() ||
+      region->in(_bad_type_path) != top()) {
+    // Let Interpreter throw ClassCastException.
+    PreserveJVMState pjvms(this);
+    set_control(_gvn.transform(region));
+    uncommon_trap(Deoptimization::Reason_intrinsic,
+                  Deoptimization::Action_maybe_recompile);
+  }
+  if (!stopped()) {
+    set_result(res);
+  }
+  return true;
+}
+
+
 //--------------------------inline_native_subtype_check------------------------
 // This intrinsic takes the JNI calls out of the heart of
 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
@@ -4611,6 +4697,10 @@
   Node* dest_offset = argument(3);  // type: int
   Node* length      = argument(4);  // type: int
 
+  // Check for allocation before we add nodes that would confuse
+  // tightly_coupled_allocation()
+  AllocateArrayNode* alloc = tightly_coupled_allocation(dest, NULL);
+
   // The following tests must be performed
   // (1) src and dest are arrays.
   // (2) src and dest arrays must have elements of the same BasicType
@@ -4784,7 +4874,6 @@
     return true;
   }
 
-  AllocateArrayNode* alloc = tightly_coupled_allocation(dest, NULL);
   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != NULL,
                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
                                           // so the compiler has a chance to eliminate them: during macro expansion,
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -506,16 +506,6 @@
 
 static AlwaysFalseClosure always_false;
 
-class VM_WhiteBoxCleanMethodData : public VM_WhiteBoxOperation {
- public:
-  VM_WhiteBoxCleanMethodData(MethodData* mdo) : _mdo(mdo) { }
-  void doit() {
-    _mdo->clean_method_data(&always_false);
-  }
- private:
-  MethodData* _mdo;
-};
-
 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
   CHECK_JNI_EXCEPTION(env);
@@ -531,8 +521,8 @@
     for (int i = 0; i < arg_count; i++) {
       mdo->set_arg_modified(i, 0);
     }
-    VM_WhiteBoxCleanMethodData op(mdo);
-    VMThread::execute(&op);
+    MutexLockerEx mu(mdo->extra_data_lock());
+    mdo->clean_method_data(&always_false);
   }
 
   mh->clear_not_c1_compilable();
@@ -800,20 +790,24 @@
   ThreadToNativeFromVM ttn(thread);
   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
   CHECK_JNI_EXCEPTION_(env, NULL);
-  result = env->NewObjectArray(2, clazz, NULL);
+  result = env->NewObjectArray(3, clazz, NULL);
   if (result == NULL) {
     return result;
   }
 
-  jobject obj = integerBox(thread, env, code->comp_level());
+  jobject level = integerBox(thread, env, code->comp_level());
   CHECK_JNI_EXCEPTION_(env, NULL);
-  env->SetObjectArrayElement(result, 0, obj);
+  env->SetObjectArrayElement(result, 0, level);
 
   jbyteArray insts = env->NewByteArray(insts_size);
   CHECK_JNI_EXCEPTION_(env, NULL);
   env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
   env->SetObjectArrayElement(result, 1, insts);
 
+  jobject id = integerBox(thread, env, code->compile_id());
+  CHECK_JNI_EXCEPTION_(env, NULL);
+  env->SetObjectArrayElement(result, 2, id);
+
   return result;
 WB_END
 
--- a/hotspot/src/share/vm/runtime/interfaceSupport.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/runtime/interfaceSupport.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -187,19 +187,22 @@
 
 # endif
 
-
+// invocation counter for InterfaceSupport::deoptimizeAll/zombieAll functions
 int deoptimizeAllCounter = 0;
 int zombieAllCounter = 0;
 
-
 void InterfaceSupport::zombieAll() {
-  if (is_init_completed() && zombieAllCounter > ZombieALotInterval) {
+  // This method is called by all threads when a thread make
+  // transition to VM state (for example, runtime calls).
+  // Divide number of calls by number of threads to avoid
+  // dependence of ZombieAll events frequency on number of threads.
+  int value = zombieAllCounter / Threads::number_of_threads();
+  if (is_init_completed() && value > ZombieALotInterval) {
     zombieAllCounter = 0;
     VM_ZombieAll op;
     VMThread::execute(&op);
-  } else {
-    zombieAllCounter++;
   }
+  zombieAllCounter++;
 }
 
 void InterfaceSupport::unlinkSymbols() {
@@ -208,12 +211,17 @@
 }
 
 void InterfaceSupport::deoptimizeAll() {
-  if (is_init_completed() ) {
-    if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) {
+  // This method is called by all threads when a thread make
+  // transition to VM state (for example, runtime calls).
+  // Divide number of calls by number of threads to avoid
+  // dependence of DeoptimizeAll events frequency on number of threads.
+  int value = deoptimizeAllCounter / Threads::number_of_threads();
+  if (is_init_completed()) {
+    if (DeoptimizeALot && value > DeoptimizeALotInterval) {
       deoptimizeAllCounter = 0;
       VM_DeoptimizeAll op;
       VMThread::execute(&op);
-    } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) {
+    } else if (DeoptimizeRandom && (value & 0x1F) == (os::random() & 0x1F)) {
       VM_DeoptimizeAll op;
       VMThread::execute(&op);
     }
--- a/hotspot/src/share/vm/runtime/simpleThresholdPolicy.cpp	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/src/share/vm/runtime/simpleThresholdPolicy.cpp	Thu Nov 06 19:59:32 2014 +0000
@@ -196,7 +196,6 @@
     // Don't trigger other compiles in testing mode
     return NULL;
   }
-  nmethod *osr_nm = NULL;
 
   handle_counter_overflow(method());
   if (method() != inlinee()) {
@@ -210,14 +209,16 @@
   if (bci == InvocationEntryBci) {
     method_invocation_event(method, inlinee, comp_level, nm, thread);
   } else {
+    // method == inlinee if the event originated in the main method
     method_back_branch_event(method, inlinee, bci, comp_level, nm, thread);
-    // method == inlinee if the event originated in the main method
-    int highest_level = inlinee->highest_osr_comp_level();
-    if (highest_level > comp_level) {
-      osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false);
+    // Check if event led to a higher level OSR compilation
+    nmethod* osr_nm = inlinee->lookup_osr_nmethod_for(bci, comp_level, false);
+    if (osr_nm != NULL && osr_nm->comp_level() > comp_level) {
+      // Perform OSR with new nmethod
+      return osr_nm;
     }
   }
-  return osr_nm;
+  return NULL;
 }
 
 // Check if the method can be compiled, change level if necessary
--- a/hotspot/test/TEST.groups	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/TEST.groups	Thu Nov 06 19:59:32 2014 +0000
@@ -478,6 +478,7 @@
   compiler/intrinsics/mathexact/SubExactILoopDependentTest.java \
   compiler/intrinsics/stringequals/TestStringEqualsBadLength.java \
   compiler/intrinsics/unsafe/UnsafeGetAddressTest.java \
+  compiler/intrinsics/classcast/NullCheckDroppingsTest.java \
   compiler/jsr292/ConcurrentClassLoadingTest.java \
   compiler/jsr292/CreatesInterfaceDotEqualsCallInfo.java \
   compiler/loopopts/TestLogSum.java \
--- a/hotspot/test/compiler/6896617/Test6896617.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/6896617/Test6896617.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,13 +25,20 @@
  * @test
  * @bug 6896617
  * @summary Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() with SSE instructions on x86
+ * @library /testlibrary
  * @run main/othervm/timeout=1200 -Xbatch -Xmx256m Test6896617
  *
  */
 
-import java.util.*;
-import java.nio.*;
-import java.nio.charset.*;
+import com.oracle.java.testlibrary.Utils;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+import java.util.Arrays;
+import java.util.Random;
 
 public class Test6896617 {
     final static int SIZE = 256;
@@ -54,7 +61,7 @@
         sun.nio.cs.ArrayDecoder arrdec = (sun.nio.cs.ArrayDecoder)dec;
 
         // Populate char[] with chars which can be encoded by ISO_8859_1 (<= 0xFF)
-        Random rnd = new Random(0);
+        Random rnd = Utils.getRandomInstance();
         int maxchar = 0xFF;
         char[] a = new char[SIZE];
         byte[] b = new byte[SIZE];
--- a/hotspot/test/compiler/7100757/Test7100757.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/7100757/Test7100757.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, 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
@@ -26,11 +26,13 @@
  * @test
  * @bug 7100757
  * @summary The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
- *
+ * @library /testlibrary
  * @run main/timeout=300 Test7100757
  */
 
-import java.util.*;
+import com.oracle.java.testlibrary.Utils;
+import java.util.BitSet;
+import java.util.Random;
 
 public class Test7100757 {
 
@@ -39,7 +41,7 @@
   public static void main(String[] args) {
 
     BitSet bs = new BitSet(NBITS);
-    Random rnd = new Random();
+    Random rnd = Utils.getRandomInstance();
     long[] ra = new long[(NBITS+63)/64];
 
     for(int l=0; l < 5000000; l++) {
--- a/hotspot/test/compiler/7177917/Test7177917.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/7177917/Test7177917.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, 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
@@ -26,13 +26,14 @@
  * Micro-benchmark for Math.pow() and Math.exp()
  */
 
-import java.util.*;
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
 
 public class Test7177917 {
 
   static double d;
 
-  static Random r = new Random(0);
+  static final Random R = Utils.getRandomInstance();
 
   static long  m_pow(double[][] values) {
     double res = 0;
@@ -59,10 +60,10 @@
   static double[][] pow_values(int nb) {
     double[][] res = new double[nb][2];
     for (int i = 0; i < nb; i++) {
-      double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
-      double x = Math.abs(Double.longBitsToDouble(r.nextLong()));
+      double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
+      double x = Math.abs(Double.longBitsToDouble(R.nextLong()));
       while (x != x) {
-        x = Math.abs(Double.longBitsToDouble(r.nextLong()));
+        x = Math.abs(Double.longBitsToDouble(R.nextLong()));
       }
       double logx = Math.log(x) / Math.log(2);
       double y = ylogx / logx;
@@ -76,7 +77,7 @@
   static double[] exp_values(int nb) {
     double[] res = new double[nb];
     for (int i = 0; i < nb; i++) {
-      double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
+      double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
       double x = Math.E;
       double logx = Math.log(x) / Math.log(2);
       double y = ylogx / logx;
--- a/hotspot/test/compiler/7184394/TestAESBase.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/7184394/TestAESBase.java	Thu Nov 06 19:59:32 2014 +0000
@@ -26,15 +26,13 @@
  * @author Tom Deneau
  */
 
+import com.oracle.java.testlibrary.Utils;
+import java.security.AlgorithmParameters;
+import java.util.Random;
 import javax.crypto.Cipher;
-import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
-import java.security.AlgorithmParameters;
-
-import java.util.Random;
-import java.util.Arrays;
 
 abstract public class TestAESBase {
   int msgSize = Integer.getInteger("msgSize", 646);
@@ -59,7 +57,7 @@
   byte[] expectedEncode;
   byte[] decode;
   byte[] expectedDecode;
-  Random random = new Random(0);
+  final Random random = Utils.getRandomInstance();
   Cipher cipher;
   Cipher dCipher;
   AlgorithmParameters algParams;
--- a/hotspot/test/compiler/7184394/TestAESMain.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/7184394/TestAESMain.java	Thu Nov 06 19:59:32 2014 +0000
@@ -26,6 +26,7 @@
  * @test
  * @bug 7184394
  * @summary add intrinsics to use AES instructions
+ * @library /testlibrary
  *
  * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC TestAESMain
  * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 TestAESMain
--- a/hotspot/test/compiler/8005956/PolynomialRoot.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/8005956/PolynomialRoot.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,4 +1,3 @@
-//package com.polytechnik.utils;
 /*
  * (C) Vladislav Malyshkin 2010
  * This file is under GPL version 3.
@@ -14,10 +13,14 @@
 * @test
 * @bug 8005956
 * @summary C2: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG defined in this block
-*
+* @library /testlibrary
 * @run main/timeout=300 PolynomialRoot
 */
 
+import com.oracle.java.testlibrary.Utils;
+import java.util.Arrays;
+import java.util.Random;
+
 public class PolynomialRoot  {
 
 
@@ -57,7 +60,7 @@
 
 public static int root4(final double [] p,final double [] re_root,final double [] im_root)
 {
-  if(PRINT_DEBUG) System.err.println("=====================root4:p="+java.util.Arrays.toString(p));
+  if (PRINT_DEBUG) { System.err.println("=====================root4:p=" + Arrays.toString(p)); }
   final double vs=p[4];
   if(PRINT_DEBUG) System.err.println("p[4]="+p[4]);
   if(!(Math.abs(vs)>EPS))
@@ -367,7 +370,7 @@
 
 
 
-    static void setRandomP(final double [] p,final int n,java.util.Random r)
+    static void setRandomP(final double [] p, final int n, Random r)
     {
   if(r.nextDouble()<0.1)
   {
@@ -465,7 +468,7 @@
 
     static void testRoots(final int n,
         final int n_tests,
-        final java.util.Random rn,
+        final Random rn,
         final double eps)
     {
   final double [] p=new double [n+1];
@@ -763,7 +766,7 @@
         final long t0=System.currentTimeMillis();
         final double eps=1e-6;
         //checkRoots();
-        final java.util.Random r=new java.util.Random(-1381923);
+        final Random r = Utils.getRandomInstance();
         printSpecialValues();
 
         final int n_tests=100000;
--- a/hotspot/test/compiler/intrinsics/bmi/BMITestRunner.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/bmi/BMITestRunner.java	Thu Nov 06 19:59:32 2014 +0000
@@ -22,13 +22,17 @@
  *
  */
 
-import java.util.*;
+import com.oracle.java.testlibrary.Asserts;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
-import java.nio.charset.StandardCharsets;
-
-import com.oracle.java.testlibrary.*;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
 
 /**
  * Test runner that invokes all methods implemented by particular Expr
@@ -69,7 +73,7 @@
                                 String... additionalVMOpts)
                          throws Throwable {
 
-        int seed = new Random().nextInt();
+        int seed = Utils.getRandomInstance().nextInt();
         int iterations = DEFAULT_ITERATIONS_COUNT;
 
         for (String testOption : testOpts) {
@@ -81,8 +85,6 @@
             }
         }
 
-        System.out.println("Running test with seed: " + seed);
-
         OutputAnalyzer intOutput = runTest(expr, VMMode.INT,
                                            additionalVMOpts,
                                            seed, iterations);
@@ -139,9 +141,9 @@
 
         Collections.addAll(vmOpts, new String[] {
                 "-XX:+DisplayVMOutputToStderr",
+                "-D" + Utils.SEED_PROPERTY_NAME + "=" + seed,
                 Executor.class.getName(),
                 expr.getName(),
-                new Integer(seed).toString(),
                 new Integer(iterations).toString()
             });
 
@@ -179,16 +181,15 @@
     public static class Executor {
 
         /**
-         * Usage: BMITestRunner$Executor <ExprClassName> <seed> <iterations>
+         * Usage: BMITestRunner$Executor &lt;ExprClassName&gt; &lt;iterations&gt;
          */
         public static void main(String args[]) throws Exception {
             @SuppressWarnings("unchecked")
             Class<? extends Expr> exprClass =
                 (Class<? extends Expr>)Class.forName(args[0]);
             Expr expr = exprClass.getConstructor().newInstance();
-            Random rng = new Random(Integer.valueOf(args[1]));
-            int iterations = Integer.valueOf(args[2]);
-            runTests(expr, iterations, rng);
+            int iterations = Integer.valueOf(args[1]);
+            runTests(expr, iterations, Utils.getRandomInstance());
         }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/intrinsics/classcast/NullCheckDroppingsTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -0,0 +1,346 @@
+/*
+ * Copyright (c) 2014, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test NullCheckDroppingsTest
+ * @bug 8054492
+ * @summary "Casting can result in redundant null checks in generated code"
+ * @library /testlibrary /testlibrary/whitebox /testlibrary/com/oracle/java/testlibrary
+ * @build NullCheckDroppingsTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main ClassFileInstaller com.oracle.java.testlibrary.Platform
+ * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
+ *                   -Xmixed -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:CompileThreshold=1000
+ *                   -XX:CompileCommand=exclude,NullCheckDroppingsTest::runTest NullCheckDroppingsTest
+ */
+
+import sun.hotspot.WhiteBox;
+import sun.hotspot.code.NMethod;
+import com.oracle.java.testlibrary.Platform;
+
+import java.lang.reflect.Method;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.function.BiFunction;
+
+public class NullCheckDroppingsTest {
+
+    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
+
+    static final BiFunction<Class, Object, Object> fCast = (c, o) -> c.cast(o);
+
+    static final MethodHandle SET_SSINK;
+    static final MethodHandle MH_CAST;
+
+    static {
+        try {
+            SET_SSINK = MethodHandles.lookup().findSetter(NullCheckDroppingsTest.class, "ssink", String.class);
+            MH_CAST = MethodHandles.lookup().findVirtual(Class.class,
+                                                         "cast",
+                                                         MethodType.methodType(Object.class, Object.class));
+        }
+        catch (Exception e) {
+            throw new Error(e);
+        }
+    }
+
+    static volatile String svalue = "A";
+    static volatile String snull = null;
+    static volatile Integer iobj = new Integer(0);
+    static volatile int[] arr = new int[2];
+    static volatile Class objClass = String.class;
+    static volatile Class nullClass = null;
+
+    String  ssink;
+    Integer isink;
+    int[]   asink;
+
+    public static void main(String[] args) throws Exception {
+
+        // Only test C2 in Server VM
+        if (!Platform.isServer()) {
+            return;
+        }
+        // Make sure background compilation is disabled
+        if (WHITE_BOX.getBooleanVMFlag("BackgroundCompilation")) {
+            throw new AssertionError("Background compilation enabled");
+        }
+        // Make sure Tiered compilation is disabled
+        if (WHITE_BOX.getBooleanVMFlag("TieredCompilation")) {
+            throw new AssertionError("Tiered compilation enabled");
+        }
+
+        Method methodClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCast", String.class);
+        Method methodMHCast    = NullCheckDroppingsTest.class.getDeclaredMethod("testMHCast",    String.class);
+        Method methodMHSetter  = NullCheckDroppingsTest.class.getDeclaredMethod("testMHSetter",  String.class);
+        Method methodFunction  = NullCheckDroppingsTest.class.getDeclaredMethod("testFunction",  String.class);
+
+        NullCheckDroppingsTest t = new NullCheckDroppingsTest();
+        t.runTest(methodClassCast, false);
+        t.runTest(methodMHCast,    false);
+        t.runTest(methodMHSetter,  false);
+        t.runTest(methodFunction,  false);
+
+        // Edge cases
+        Method methodClassCastNull = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastNull", String.class);
+        Method methodNullClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testNullClassCast", String.class);
+        Method methodClassCastObj  = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastObj",  Object.class);
+        Method methodObjClassCast  = NullCheckDroppingsTest.class.getDeclaredMethod("testObjClassCast",  String.class);
+        Method methodVarClassCast  = NullCheckDroppingsTest.class.getDeclaredMethod("testVarClassCast",  String.class);
+        Method methodClassCastInt  = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastInt",  Object.class);
+        Method methodIntClassCast  = NullCheckDroppingsTest.class.getDeclaredMethod("testIntClassCast",  Object.class);
+        Method methodClassCastint  = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastint",  Object.class);
+        Method methodintClassCast  = NullCheckDroppingsTest.class.getDeclaredMethod("testintClassCast",  Object.class);
+        Method methodClassCastPrim = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastPrim", Object.class);
+        Method methodPrimClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testPrimClassCast", Object.class);
+
+        t.runTest(methodClassCastNull, false);
+        t.runTest(methodNullClassCast, false);
+        t.runTest(methodClassCastObj,  false);
+        t.runTest(methodObjClassCast,  true);
+        t.runTest(methodVarClassCast,  true);
+        t.runTest(methodClassCastInt,  false);
+        t.runTest(methodIntClassCast,  true);
+        t.runTest(methodClassCastint,  false);
+        t.runTest(methodintClassCast,  false);
+        t.runTest(methodClassCastPrim, false);
+        t.runTest(methodPrimClassCast, true);
+    }
+
+    void testClassCast(String s) {
+        try {
+            ssink = String.class.cast(s);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testClassCastNull(String s) {
+        try {
+            ssink = String.class.cast(null);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testNullClassCast(String s) {
+        try {
+            ssink = (String)nullClass.cast(s);
+            throw new AssertionError("NullPointerException is not thrown");
+        } catch (NullPointerException t) {
+            // Ignore NullPointerException
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testClassCastObj(Object s) {
+        try {
+            ssink = String.class.cast(s);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testObjClassCast(String s) {
+        try {
+            ssink = (String)objClass.cast(s);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testVarClassCast(String s) {
+        Class cl = (s == null) ? null : String.class;
+        try {
+            ssink = (String)cl.cast(svalue);
+            if (s == null) {
+                throw new AssertionError("NullPointerException is not thrown");
+            }
+        } catch (NullPointerException t) {
+            // Ignore NullPointerException
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testClassCastInt(Object s) {
+        try {
+            ssink = String.class.cast(iobj);
+            throw new AssertionError("ClassCastException is not thrown");
+        } catch (ClassCastException t) {
+            // Ignore ClassCastException: Cannot cast java.lang.Integer to java.lang.String
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testIntClassCast(Object s) {
+        try {
+            isink = Integer.class.cast(s);
+            if (s != null) {
+                throw new AssertionError("ClassCastException is not thrown");
+            }
+        } catch (ClassCastException t) {
+            // Ignore ClassCastException: Cannot cast java.lang.String to java.lang.Integer
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testClassCastint(Object s) {
+        try {
+            ssink = String.class.cast(45);
+            throw new AssertionError("ClassCastException is not thrown");
+        } catch (ClassCastException t) {
+            // Ignore ClassCastException: Cannot cast java.lang.Integer to java.lang.String
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testintClassCast(Object s) {
+        try {
+            isink = int.class.cast(s);
+            if (s != null) {
+                throw new AssertionError("ClassCastException is not thrown");
+            }
+        } catch (ClassCastException t) {
+            // Ignore ClassCastException: Cannot cast java.lang.String to java.lang.Integer
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testClassCastPrim(Object s) {
+        try {
+            ssink = String.class.cast(arr);
+            throw new AssertionError("ClassCastException is not thrown");
+        } catch (ClassCastException t) {
+            // Ignore ClassCastException: Cannot cast [I to java.lang.String
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testPrimClassCast(Object s) {
+        try {
+            asink = int[].class.cast(s);
+            if (s != null) {
+                throw new AssertionError("ClassCastException is not thrown");
+            }
+        } catch (ClassCastException t) {
+            // Ignore ClassCastException: Cannot cast java.lang.String to [I
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testMHCast(String s) {
+        try {
+            ssink = (String) (Object) MH_CAST.invokeExact(String.class, (Object) s);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testMHSetter(String s) {
+        try {
+            SET_SSINK.invokeExact(this, s);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void testFunction(String s) {
+        try {
+            ssink = (String) fCast.apply(String.class, s);
+        } catch (Throwable t) {
+            throw new Error(t);
+        }
+    }
+
+    void runTest(Method method, boolean deopt) {
+        if (method == null) {
+            throw new AssertionError("method was not found");
+        }
+        // Ensure method is compiled
+        WHITE_BOX.testSetDontInlineMethod(method, true);
+        for (int i = 0; i < 3000; i++) {
+            try {
+                method.invoke(this, svalue);
+            } catch (Exception e) {
+                throw new Error("Unexpected exception: ", e);
+            }
+        }
+        NMethod nm = getNMethod(method);
+
+        // Passing null should cause a de-optimization
+        // if method is compiled with a null-check.
+        try {
+            method.invoke(this, snull);
+        } catch (Exception e) {
+            throw new Error("Unexpected exception: ", e);
+        }
+        checkDeoptimization(method, nm, deopt);
+    }
+
+    static NMethod getNMethod(Method test) {
+        // Because background compilation is disabled, method should now be compiled
+        if (!WHITE_BOX.isMethodCompiled(test)) {
+            throw new AssertionError(test + " not compiled");
+        }
+
+        NMethod nm = NMethod.get(test, false); // not OSR nmethod
+        if (nm == null) {
+            throw new AssertionError(test + " missing nmethod?");
+        }
+        if (nm.comp_level != 4) {
+            throw new AssertionError(test + " compiled by not C2: " + nm);
+        }
+        return nm;
+    }
+
+    static void checkDeoptimization(Method method, NMethod nmOrig, boolean deopt) {
+        // Check deoptimization event (intrinsic Class.cast() works).
+        if (WHITE_BOX.isMethodCompiled(method) == deopt) {
+            throw new AssertionError(method + " was" + (deopt ? " not" : "") + " deoptimized");
+        }
+        if (deopt) {
+            return;
+        }
+        // Ensure no recompilation when no deoptimization is expected.
+        NMethod nm = NMethod.get(method, false); // not OSR nmethod
+        if (nm == null) {
+            throw new AssertionError(method + " missing nmethod?");
+        }
+        if (nm.comp_level != 4) {
+            throw new AssertionError(method + " compiled by not C2: " + nm);
+        }
+        if (nm.compile_id != nmOrig.compile_id) {
+            throw new AssertionError(method + " was recompiled: old nmethod=" + nmOrig + ", new nmethod=" + nm);
+        }
+    }
+}
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactIConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactIConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8024924
  * @summary Test constant addExact
+ * @library /testlibrary
  * @compile AddExactIConstantTest.java Verify.java
  * @run main AddExactIConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactILoadTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactILoadTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8024924
  * @summary Test non constant addExact
+ * @library /testlibrary
  * @compile AddExactILoadTest.java Verify.java
  * @run main AddExactILoadTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactILoopDependentTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactILoopDependentTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8024924
  * @summary Test non constant addExact
+ * @library /testlibrary
  * @compile AddExactILoopDependentTest.java Verify.java
  * @run main AddExactILoopDependentTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactINonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactINonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8024924
  * @summary Test non constant addExact
+ * @library /testlibrary
  * @compile AddExactINonConstantTest.java Verify.java
  * @run main AddExactINonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactIRepeatTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactIRepeatTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,11 +25,15 @@
  * @test
  * @bug 8025657
  * @summary Test repeating addExact
+ * @library /testlibrary
  * @compile AddExactIRepeatTest.java Verify.java
  * @run main AddExactIRepeatTest
  *
  */
 
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
+
 public class AddExactIRepeatTest {
     public static void main(String[] args) {
         runTest(new Verify.AddExactI());
@@ -44,7 +48,7 @@
     }
 
     public static void runTest(Verify.BinaryMethod method) {
-        java.util.Random rnd = new java.util.Random();
+        Random rnd = Utils.getRandomInstance();
         for (int i = 0; i < 50000; ++i) {
             int x = Integer.MAX_VALUE - 10;
             int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactLConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactLConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant addExact
+ * @library /testlibrary
  * @compile AddExactLConstantTest.java Verify.java
  * @run main AddExactLConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/AddExactLNonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/AddExactLNonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant addExact
+ * @library /testlibrary
  * @compile AddExactLNonConstantTest.java Verify.java
  * @run main AddExactLNonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/DecExactITest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/DecExactITest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test decrementExact
+ * @library /testlibrary
  * @compile DecExactITest.java Verify.java
  * @run main DecExactITest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/DecExactLTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/DecExactLTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test decrementExact
+ * @library /testlibrary
  * @compile DecExactLTest.java Verify.java
  * @run main DecExactLTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/IncExactITest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/IncExactITest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test incrementExact
+ * @library /testlibrary
  * @compile IncExactITest.java Verify.java
  * @run main IncExactITest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/IncExactLTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/IncExactLTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test incrementExact
+ * @library /testlibrary
  * @compile IncExactLTest.java Verify.java
  * @run main IncExactLTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactIConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactIConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant multiplyExact
+ * @library /testlibrary
  * @compile MulExactIConstantTest.java Verify.java
  * @run main MulExactIConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactILoadTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactILoadTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test multiplyExact
+ * @library /testlibrary
  * @compile MulExactILoadTest.java Verify.java
  * @run main MulExactILoadTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactILoopDependentTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactILoopDependentTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test loop dependent multiplyExact
+ * @library /testlibrary
  * @compile MulExactILoopDependentTest.java Verify.java
  * @run main MulExactILoopDependentTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactINonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactINonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant multiplyExact
+ * @library /testlibrary
  * @compile MulExactINonConstantTest.java Verify.java
  * @run main MulExactINonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactIRepeatTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactIRepeatTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,11 +25,15 @@
  * @test
  * @bug 8026844
  * @summary Test repeating multiplyExact
+ * @library /testlibrary
  * @compile MulExactIRepeatTest.java Verify.java
  * @run main MulExactIRepeatTest
  *
  */
 
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
+
 public class MulExactIRepeatTest {
     public static void main(String[] args) {
         runTest(new Verify.MulExactI());
@@ -44,7 +48,7 @@
     }
 
     public static void runTest(Verify.BinaryMethod method) {
-        java.util.Random rnd = new java.util.Random();
+        Random rnd = Utils.getRandomInstance();
         for (int i = 0; i < 50000; ++i) {
             int x = Integer.MAX_VALUE - 10;
             int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactLConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactLConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant mulExact
+ * @library /testlibrary
  * @compile MulExactLConstantTest.java Verify.java
  * @run main MulExactLConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/MulExactLNonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/MulExactLNonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant mulExact
+ * @library /testlibrary
  * @compile MulExactLNonConstantTest.java Verify.java
  * @run main MulExactLNonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactIConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactIConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant negExact
+ * @library /testlibrary
  * @compile NegExactIConstantTest.java Verify.java
  * @run main NegExactIConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactILoadTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactILoadTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test negExact
+ * @library /testlibrary
  * @compile NegExactILoadTest.java Verify.java
  * @run main NegExactILoadTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactILoopDependentTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactILoopDependentTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test negExact loop dependent
+ * @library /testlibrary
  * @compile NegExactILoopDependentTest.java Verify.java
  * @run main NegExactILoopDependentTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactINonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactINonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant negExact
+ * @library /testlibrary
  * @compile NegExactINonConstantTest.java Verify.java
  * @run main NegExactINonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactLConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactLConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant negExact
+ * @library /testlibrary
  * @compile NegExactLConstantTest.java Verify.java
  * @run main NegExactLConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/NegExactLNonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/NegExactLNonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant negExact
+ * @library /testlibrary
  * @compile NegExactLNonConstantTest.java Verify.java
  * @run main NegExactLNonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactICondTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactICondTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test subtractExact as condition
+ * @library /testlibrary
  * @compile SubExactICondTest.java Verify.java
  * @run main SubExactICondTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactIConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactIConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test constant subtractExact
+ * @library /testlibrary
  * @compile SubExactIConstantTest.java Verify.java
  * @run main SubExactIConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactILoadTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactILoadTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant subtractExact
+ * @library /testlibrary
  * @compile SubExactILoadTest.java Verify.java
  * @run main SubExactILoadTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactILoopDependentTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactILoopDependentTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant subtractExact
+ * @library /testlibrary
  * @compile SubExactILoopDependentTest.java Verify.java
  * @run main SubExactILoopDependentTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactINonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactINonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 8026844
  * @summary Test non constant subtractExact
+ * @library /testlibrary
  * @compile SubExactINonConstantTest.java Verify.java
  * @run main SubExactINonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactIRepeatTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactIRepeatTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,12 +25,14 @@
  * @test
  * @bug 8026844
  * @summary Test repeating subtractExact
+ * @library /testlibrary
  * @compile SubExactIRepeatTest.java Verify.java
  * @run main SubExactIRepeatTest
  *
  */
 
-import java.lang.ArithmeticException;
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
 
 public class SubExactIRepeatTest {
     public static void main(String[] args) {
@@ -46,7 +48,7 @@
     }
 
     public static void runTest(Verify.BinaryMethod method) {
-        java.util.Random rnd = new java.util.Random();
+        Random rnd = Utils.getRandomInstance();
         for (int i = 0; i < 50000; ++i) {
             int x = Integer.MIN_VALUE + 10;
             int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactLConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactLConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -26,6 +26,7 @@
  * @bug 8026844
  * @bug 8027353
  * @summary Test constant subtractExact
+ * @library /testlibrary
  * @compile SubExactLConstantTest.java Verify.java
  * @run main SubExactLConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/SubExactLNonConstantTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/SubExactLNonConstantTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -26,6 +26,7 @@
  * @bug 8026844
  * @bug 8027353
  * @summary Test non constant subtractExact
+ * @library /testlibrary
  * @compile SubExactLNonConstantTest.java Verify.java
  * @run main SubExactLNonConstantTest
  *
--- a/hotspot/test/compiler/intrinsics/mathexact/Verify.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/intrinsics/mathexact/Verify.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -21,6 +21,13 @@
  * questions.
  */
 
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
+
+/**
+ * The class depends on Utils class from testlibrary package.
+ * It uses factory method that obtains random generator.
+ */
 public class Verify {
     public static String throwWord(boolean threw) {
         return (threw ? "threw" : "didn't throw");
@@ -134,7 +141,7 @@
 
 
     public static class LoadTest {
-        public static java.util.Random rnd = new java.util.Random();
+        public static Random rnd = Utils.getRandomInstance();
         public static int[] values = new int[256];
 
         public static void init() {
@@ -159,7 +166,7 @@
     }
 
     public static class NonConstantTest {
-        public static java.util.Random rnd = new java.util.Random();
+        public static Random rnd = Utils.getRandomInstance();
         public static int[] values = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE };
 
         public static void verify(BinaryMethod method) {
@@ -180,7 +187,7 @@
 
     public static class NonConstantLongTest {
         public static long[] values = { Long.MIN_VALUE, Long.MAX_VALUE, 0, Long.MAX_VALUE - 1831 };
-        public static java.util.Random rnd = new java.util.Random();
+        public static Random rnd = Utils.getRandomInstance();
 
         public static void verify(BinaryLongMethod method) {
             for (int i = 0; i < 50000; ++i) {
@@ -199,7 +206,7 @@
     }
 
     public static class LoopDependentTest {
-        public static java.util.Random rnd = new java.util.Random();
+        public static Random rnd = Utils.getRandomInstance();
 
         public static void verify(BinaryMethod method) {
             int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt();
--- a/hotspot/test/compiler/jsr292/ConcurrentClassLoadingTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/jsr292/ConcurrentClassLoadingTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,18 +25,21 @@
  * @test
  * @bug 8022595
  * @summary JSR292: deadlock during class loading of MethodHandles, MethodHandleImpl & MethodHandleNatives
- *
+ * @library /testlibrary
  * @run main/othervm ConcurrentClassLoadingTest
  */
-import java.util.*;
+import com.oracle.java.testlibrary.Utils;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.CyclicBarrier;
 
 public class ConcurrentClassLoadingTest {
     int numThreads = 0;
-    long seed = 0;
     CyclicBarrier l;
-    Random rand;
+    private static final Random rand = Utils.getRandomInstance();
 
     public static void main(String[] args) throws Throwable {
         ConcurrentClassLoadingTest test = new ConcurrentClassLoadingTest();
@@ -49,9 +52,6 @@
         while (i < args.length) {
             String flag = args[i];
             switch(flag) {
-                case "-seed":
-                    seed = Long.parseLong(args[++i]);
-                    break;
                 case "-numThreads":
                     numThreads = Integer.parseInt(args[++i]);
                     break;
@@ -67,15 +67,9 @@
             numThreads = Runtime.getRuntime().availableProcessors();
         }
 
-        if (seed == 0) {
-            seed = (new Random()).nextLong();
-        }
-        rand = new Random(seed);
-
         l = new CyclicBarrier(numThreads + 1);
 
         System.out.printf("Threads: %d\n", numThreads);
-        System.out.printf("Seed: %d\n", seed);
     }
 
     final List<Loader> loaders = new ArrayList<>();
@@ -90,7 +84,9 @@
 
             System.out.printf("Thread #%d:\n", t);
             for (int i = 0; i < count; i++) {
-                if (c.size() == 0) break;
+                if (c.isEmpty()) {
+                    break;
+                }
 
                 int k = rand.nextInt(c.size());
                 String elem = c.remove(k);
--- a/hotspot/test/compiler/types/correctness/OffTest.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/types/correctness/OffTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -36,10 +36,10 @@
 
 import com.oracle.java.testlibrary.OutputAnalyzer;
 import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
+import java.util.Random;
 import scenarios.ProfilingType;
 
-import java.util.Random;
-
 public class OffTest {
     private static final String[] OPTIONS = {
             "-Xbootclasspath/a:.",
@@ -63,14 +63,7 @@
     private static final int PROFILING_TYPE_INDEX = OPTIONS.length - 1;
     private static final int TYPE_PROFILE_INDEX = OPTIONS.length - 4;
     private static final int USE_TYPE_SPECULATION_INDEX = OPTIONS.length - 3;
-    private static final Random RNG;
-
-    static {
-        String str = System.getProperty("seed");
-        long seed = str != null ? Long.parseLong(str) : new Random().nextLong();
-        RNG = new Random(seed);
-        System.out.printf("-Dseed=%d%n", seed);
-    }
+    private static final Random RNG = Utils.getRandomInstance();
 
     public static void main(String[] args) throws Exception {
         int count = DEFAULT_COUNT;
--- a/hotspot/test/compiler/unsafe/UnsafeRaw.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/compiler/unsafe/UnsafeRaw.java	Thu Nov 06 19:59:32 2014 +0000
@@ -80,7 +80,7 @@
     final int element_size = 4;
     final int magic = 0x12345678;
 
-    Random rnd = new Random();
+    Random rnd = Utils.getRandomInstance();
 
     long array = unsafe.allocateMemory(array_size * element_size); // 128 ints
     long addr = array + array_size * element_size / 2; // something in the middle to work with
--- a/hotspot/test/serviceability/threads/TestFalseDeadLock.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/serviceability/threads/TestFalseDeadLock.java	Thu Nov 06 19:59:32 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -21,6 +21,7 @@
  * questions.
  */
 
+import com.oracle.java.testlibrary.Utils;
 import java.lang.management.ManagementFactory;
 import java.lang.management.ThreadMXBean;
 import java.util.Random;
@@ -30,6 +31,7 @@
  * @ignore 8061157
  * @bug 8016304
  * @summary Make sure no deadlock is reported for this program which has no deadlocks.
+ * @library /testlibrary
  * @run main/othervm TestFalseDeadLock
  */
 
@@ -66,7 +68,7 @@
 
     public static class Test implements Runnable {
         public void run() {
-            Random r = new Random();
+            Random r = Utils.getRandomInstance();
             while (running) {
                 try {
                     synchronized (this) {
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java	Thu Nov 06 19:59:32 2014 +0000
@@ -24,21 +24,21 @@
 package com.oracle.java.testlibrary;
 
 import static com.oracle.java.testlibrary.Asserts.assertTrue;
-
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
-import java.util.List;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.regex.Pattern;
+import java.util.List;
+import java.util.Random;
 import java.util.regex.Matcher;
-import java.lang.reflect.Field;
+import java.util.regex.Pattern;
 import sun.misc.Unsafe;
 
 /**
@@ -64,6 +64,21 @@
     private static Unsafe unsafe = null;
 
     /**
+     * Defines property name for seed value.
+     */
+    public static final String SEED_PROPERTY_NAME = "com.oracle.java.testlibrary.random.seed";
+
+    /* (non-javadoc)
+     * Random generator with (or without) predefined seed. Depends on
+     * "com.oracle.java.testlibrary.random.seed" property value.
+     */
+    private static volatile Random RANDOM_GENERATOR;
+
+    /**
+     * Contains the seed value used for {@link java.util.Random} creation.
+     */
+    public static final long SEED = Long.getLong(SEED_PROPERTY_NAME, new Random().nextLong());
+    /**
     * Returns the value of 'test.timeout.factor' system property
     * converted to {@code double}.
     */
@@ -332,4 +347,24 @@
         }
         return new String(hexView);
     }
+
+    /**
+     * Returns {@link java.util.Random} generator initialized with particular seed.
+     * The seed could be provided via system property {@link Utils#SEED_PROPERTY_NAME}
+     * In case no seed is provided, the method uses a random number.
+     * The used seed printed to stdout.
+     * @return {@link java.util.Random} generator with particular seed.
+     */
+    public static Random getRandomInstance() {
+        if (RANDOM_GENERATOR == null) {
+            synchronized (Utils.class) {
+                if (RANDOM_GENERATOR == null) {
+                    RANDOM_GENERATOR = new Random(SEED);
+                    System.out.printf("For random generator using seed: %d%n", SEED);
+                    System.out.printf("To re-run test with same seed value please add \"-D%s=%d\" to command line.%n", SEED_PROPERTY_NAME, SEED);
+                }
+            }
+        }
+        return RANDOM_GENERATOR;
+    }
 }
--- a/hotspot/test/testlibrary/whitebox/sun/hotspot/code/NMethod.java	Thu Nov 06 13:57:26 2014 +0000
+++ b/hotspot/test/testlibrary/whitebox/sun/hotspot/code/NMethod.java	Thu Nov 06 19:59:32 2014 +0000
@@ -34,18 +34,21 @@
     return obj == null ? null : new NMethod(obj);
   }
   private NMethod(Object[] obj) {
-    assert obj.length == 2;
+    assert obj.length == 3;
     comp_level = (Integer) obj[0];
     insts = (byte[]) obj[1];
+    compile_id = (Integer) obj[2];
   }
   public byte[] insts;
   public int comp_level;
+  public int compile_id;
 
   @Override
   public String toString() {
     return "NMethod{" +
         "insts=" + insts +
         ", comp_level=" + comp_level +
+        ", compile_id=" + compile_id +
         '}';
   }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/testlibrary_tests/RandomGeneratorTest.java	Thu Nov 06 19:59:32 2014 +0000
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2014, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Verify correctnes of the random generator from Utility.java
+ * @library /testlibrary
+ * @run driver RandomGeneratorTest SAME_SEED
+ * @run driver RandomGeneratorTest NO_SEED
+ * @run driver RandomGeneratorTest DIFFERENT_SEED
+ */
+
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * The test verifies correctness of work {@link com.oracle.java.testlibrary.Utils#getRandomInstance()}.
+ * Test works in three modes: same seed provided, no seed provided and
+ * different seed provided. In the first case the test expects that all random numbers
+ * will be repeated in all next iterations. For other two modes test expects that
+ * randomly generated numbers differ from original.
+ */
+public class RandomGeneratorTest {
+    private static final String SEED_VM_OPTION = "-D" + Utils.SEED_PROPERTY_NAME + "=";
+
+    public static void main( String[] args) throws Throwable {
+        if (args.length == 0) {
+            throw new Error("TESTBUG: No test mode provided.");
+        }
+        SeedOption seedOpt = SeedOption.valueOf(args[0]);
+        List<String> jvmArgs = new ArrayList<String>();
+        String optStr = seedOpt.getSeedOption();
+        if (optStr != null) {
+            jvmArgs.add(optStr);
+        }
+        jvmArgs.add(RandomRunner.class.getName());
+        String[] cmdLineArgs = jvmArgs.toArray(new String[jvmArgs.size()]);
+        String etalon = ProcessTools.executeTestJvm(cmdLineArgs).getOutput().trim();
+        seedOpt.verify(etalon, cmdLineArgs);
+    }
+
+    /**
+     * The utility enum helps to generate an appropriate string that should be passed
+     * to the command line depends on the testing mode. It is also responsible for the result
+     * validation.
+     */
+    private enum SeedOption {
+        SAME_SEED {
+            @Override
+            public String getSeedOption() {
+                return SEED_VM_OPTION + Utils.SEED;
+            }
+
+            @Override
+            protected boolean isOutputExpected(String orig, String output) {
+                return output.equals(orig);
+            }
+        },
+        DIFFERENT_SEED {
+            @Override
+            public String getSeedOption() {
+                return SEED_VM_OPTION + Utils.getRandomInstance().nextLong();
+            }
+
+            @Override
+            public void verify(String orig, String[] cmdLine) {
+                cmdLine[0] = getSeedOption();
+                super.verify(orig, cmdLine);
+            }
+        },
+        NO_SEED {
+            @Override
+            public String getSeedOption() {
+                return null;
+            }
+        };
+
+        /**
+         * Generates a string to be added as a command line argument.
+         * It contains "-D" prefix, system property name, '=' sign
+         * and seed value.
+         * @return command line argument
+         */
+        public abstract String getSeedOption();
+
+        protected boolean isOutputExpected(String orig, String output) {
+            return !output.equals(orig);
+        }
+
+        /**
+         * Verifies that the original output meets expectations
+         * depending on the test mode. It compares the output of second execution
+         * to original one.
+         * @param orig original output
+         * @param cmdLine command line arguments
+         * @throws Throwable - Throws an exception in case test failure.
+         */
+        public void verify(String orig, String[] cmdLine) {
+            String lastLineOrig = getLastLine(orig);
+            String lastLine;
+            try {
+                lastLine = getLastLine(ProcessTools.executeTestJvm(cmdLine).getOutput().trim());
+            } catch (Throwable t) {
+                throw new Error("TESTBUG: Unexpedted exception during jvm execution.", t);
+            }
+            if (!isOutputExpected(lastLineOrig, lastLine)) {
+                    throw new AssertionError("Unexpected random number sequence for mode: " + this.name());
+            }
+        }
+
+        private static String getLastLine(String output) {
+            return output.substring(output.lastIndexOf(Utils.NEW_LINE)).trim();
+        }
+    }
+
+    /**
+     * The helper class generates several random numbers
+     * and prints them out.
+     */
+    public static class RandomRunner {
+        private static final int COUNT = 10;
+        public static void main(String[] args) {
+            StringBuilder sb = new StringBuilder();
+            Random rng = Utils.getRandomInstance();
+            for (int i = 0; i < COUNT; i++) {
+                sb.append(rng.nextLong()).append(' ');
+            }
+            System.out.println(sb.toString());
+        }
+    }
+}