Merge
authorbobv
Wed, 22 Feb 2017 12:34:32 -0500
changeset 46276 b223ed3405bf
parent 46275 d27ab535d88c (current diff)
parent 46274 534d019edb92 (diff)
child 46278 6db7a35e08ae
Merge
--- a/hotspot/src/cpu/aarch64/vm/jvmciCodeInstaller_aarch64.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/cpu/aarch64/vm/jvmciCodeInstaller_aarch64.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -55,7 +55,7 @@
     }
   }
 #endif // ASSERT
-  Handle obj = HotSpotObjectConstantImpl::object(constant);
+  Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
   jobject value = JNIHandles::make_local(obj());
   MacroAssembler::patch_oop(pc, (address)obj());
   int oop_index = _oop_recorder->find_index(value);
--- a/hotspot/src/cpu/s390/vm/assembler_s390.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/cpu/s390/vm/assembler_s390.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -28,8 +28,6 @@
 
 #undef  LUCY_DBG
 
-#define NearLabel Label
-
 // Immediate is an abstraction to represent the various immediate
 // operands which exist on z/Architecture. Neither this class nor
 // instances hereof have an own state. It consists of methods only.
--- a/hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1616,6 +1616,8 @@
   if (branch_target.is_bound()) {
     address branch_addr = target(branch_target);
     branch_optimized(cond, branch_addr);
+  } else if (branch_target.is_near()) {
+    z_brc(cond, branch_target);  // Caller assures that the target will be in range for z_brc.
   } else {
     z_brcl(cond, branch_target); // Let's hope target is in range. Otherwise, we will abort at patch time.
   }
@@ -1674,7 +1676,8 @@
                                                   bool     has_sign) {
   address      branch_origin = pc();
   bool         x2_imm8       = (has_sign && Immediate::is_simm8(x2)) || (!has_sign && Immediate::is_uimm8(x2));
-  bool         is_RelAddr16  = (branch_target.is_bound() &&
+  bool         is_RelAddr16  = branch_target.is_near() ||
+                               (branch_target.is_bound() &&
                                 RelAddr::is_in_range_of_RelAddr16(target(branch_target), branch_origin));
   unsigned int casenum       = (len64?2:0)+(has_sign?0:1);
 
@@ -1744,13 +1747,21 @@
                                                   Label&   branch_target,
                                                   bool     len64,
                                                   bool     has_sign) {
-  unsigned int casenum = (len64?2:0)+(has_sign?0:1);
+  unsigned int casenum = (len64 ? 2 : 0) + (has_sign ? 0 : 1);
 
   if (branch_target.is_bound()) {
     address branch_addr = target(branch_target);
     compare_and_branch_optimized(r1, r2, cond, branch_addr, len64, has_sign);
   } else {
-    {
+    if (VM_Version::has_CompareBranch() && branch_target.is_near()) {
+      switch (casenum) {
+        case 0: z_crj(  r1, r2, cond, branch_target); break;
+        case 1: z_clrj( r1, r2, cond, branch_target); break;
+        case 2: z_cgrj( r1, r2, cond, branch_target); break;
+        case 3: z_clgrj(r1, r2, cond, branch_target); break;
+        default: ShouldNotReachHere(); break;
+      }
+    } else {
       switch (casenum) {
         case 0: z_cr( r1, r2); break;
         case 1: z_clr(r1, r2); break;
--- a/hotspot/src/cpu/sparc/vm/jvmciCodeInstaller_sparc.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/cpu/sparc/vm/jvmciCodeInstaller_sparc.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -44,7 +44,7 @@
 
 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS) {
   address pc = _instructions->start() + pc_offset;
-  Handle obj = HotSpotObjectConstantImpl::object(constant);
+  Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
   jobject value = JNIHandles::make_local(obj());
   if (HotSpotObjectConstantImpl::compressed(constant)) {
 #ifdef _LP64
--- a/hotspot/src/cpu/x86/vm/jvmciCodeInstaller_x86.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/cpu/x86/vm/jvmciCodeInstaller_x86.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -65,7 +65,7 @@
 
 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS) {
   address pc = _instructions->start() + pc_offset;
-  Handle obj = HotSpotObjectConstantImpl::object(constant);
+  Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
   jobject value = JNIHandles::make_local(obj());
   if (HotSpotObjectConstantImpl::compressed(constant)) {
 #ifdef _LP64
--- a/hotspot/src/share/vm/aot/aotCodeHeap.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/aot/aotCodeHeap.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -595,9 +595,9 @@
     memcpy(&meta_name[klass_len + 1 + method_name_len], signature_name, signature_name_len);
     meta_name[klass_len + 1 + method_name_len + signature_name_len] = '\0';
     Handle exception = Exceptions::new_exception(thread, vmSymbols::java_lang_NoSuchMethodError(), meta_name);
-    java_lang_Throwable::print(exception, tty);
+    java_lang_Throwable::print(exception(), tty);
     tty->cr();
-    java_lang_Throwable::print_stack_trace(exception(), tty);
+    java_lang_Throwable::print_stack_trace(exception, tty);
     tty->cr();
     fatal("Failed to find method '%s'", meta_name);
   }
--- a/hotspot/src/share/vm/asm/assembler.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/asm/assembler.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -93,6 +93,10 @@
   GrowableArray<int>* _patch_overflow;
 
   Label(const Label&) { ShouldNotReachHere(); }
+ protected:
+
+  // The label will be bound to a location near its users.
+  bool _is_near;
 
  public:
 
@@ -126,6 +130,10 @@
   bool is_unbound() const  { return _loc == -1 && _patch_index > 0; }
   bool is_unused() const   { return _loc == -1 && _patch_index == 0; }
 
+  // The label will be bound to a location near its users. Users can
+  // optimize on this information, e.g. generate short branches.
+  bool is_near()           { return _is_near; }
+
   /**
    * Adds a reference to an unresolved displacement instruction to
    * this unbound label
@@ -145,6 +153,7 @@
     _loc = -1;
     _patch_index = 0;
     _patch_overflow = NULL;
+    _is_near = false;
   }
 
   Label() {
@@ -152,6 +161,13 @@
   }
 };
 
+// A NearLabel must be bound to a location near its users. Users can
+// optimize on this information, e.g. generate short branches.
+class NearLabel : public Label {
+ public:
+  NearLabel() : Label() { _is_near = true; }
+};
+
 // A union type for code which has to assemble both constant and
 // non-constant operands, when the distinction cannot be made
 // statically.
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -4289,6 +4289,8 @@
   }
 #endif // INCLUDE_TRACE
 
+  CompileTask::print_inlining_ul(callee, scope()->level(), bci(), msg);
+
   if (!compilation()->directive()->PrintInliningOption) {
     return;
   }
--- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -961,13 +961,13 @@
         assert(cache_index >= 0 && cache_index < pool->cache()->length(), "unexpected cache index");
         ConstantPoolCacheEntry* cpce = pool->cache()->entry_at(cache_index);
         cpce->set_method_handle(pool, info);
-        appendix = cpce->appendix_if_resolved(pool); // just in case somebody already resolved the entry
+        appendix = Handle(THREAD, cpce->appendix_if_resolved(pool)); // just in case somebody already resolved the entry
         break;
       }
       case Bytecodes::_invokedynamic: {
         ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
         cpce->set_dynamic_call(pool, info);
-        appendix = cpce->appendix_if_resolved(pool); // just in case somebody already resolved the entry
+        appendix = Handle(THREAD, cpce->appendix_if_resolved(pool)); // just in case somebody already resolved the entry
         break;
       }
       default: fatal("unexpected bytecode for load_appendix_patching_id");
--- a/hotspot/src/share/vm/ci/ciEnv.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/ci/ciEnv.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -276,7 +276,7 @@
     if (!HAS_PENDING_EXCEPTION && k != NULL) {
       oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD);
       if (!HAS_PENDING_EXCEPTION)
-        objh = JNIHandles::make_global(obj);
+        objh = JNIHandles::make_global(Handle(THREAD, obj));
     }
     if (HAS_PENDING_EXCEPTION) {
       CLEAR_PENDING_EXCEPTION;
--- a/hotspot/src/share/vm/ci/ciInstance.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/ci/ciInstance.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -58,8 +58,8 @@
 // ------------------------------------------------------------------
 // ciInstance::field_value_impl
 ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
-  Handle obj = get_oop();
-  assert(!obj.is_null(), "bad oop");
+  oop obj = get_oop();
+  assert(obj != NULL, "bad oop");
   switch(field_btype) {
     case T_BYTE:    return ciConstant(field_btype, obj->byte_field(offset));
     case T_CHAR:    return ciConstant(field_btype, obj->char_field(offset));
--- a/hotspot/src/share/vm/ci/ciObject.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/ci/ciObject.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -54,7 +54,8 @@
   if (ciObjectFactory::is_initialized()) {
     _handle = JNIHandles::make_local(o);
   } else {
-    _handle = JNIHandles::make_global(o);
+    Handle obj(Thread::current(), o);
+    _handle = JNIHandles::make_global(obj);
   }
   _klass = NULL;
   init_flags_from(o);
--- a/hotspot/src/share/vm/ci/ciObjectFactory.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/ci/ciObjectFactory.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -249,7 +249,7 @@
 
   // The ciObject does not yet exist.  Create it and insert it
   // into the cache.
-  Handle keyHandle(key);
+  Handle keyHandle(Thread::current(), key);
   ciObject* new_object = create_new_object(keyHandle());
   assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
   init_ident_of(new_object);
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -834,7 +834,7 @@
         const Klass* const k =
           SystemDictionary::resolve_super_or_fail(_class_name,
                                                   unresolved_klass,
-                                                  _loader_data->class_loader(),
+                                                  Handle(THREAD, _loader_data->class_loader()),
                                                   _protection_domain,
                                                   false,
                                                   CHECK);
@@ -2851,7 +2851,6 @@
                                                    NULL,
                                                    CHECK);
 
-    HandleMark hm(THREAD);
     for (int index = 0; index < length; index++) {
       Method* method = parse_method(cfs,
                                     is_interface,
@@ -5357,7 +5356,7 @@
   // Allocate mirror and initialize static fields
   // The create_mirror() call will also call compute_modifiers()
   java_lang_Class::create_mirror(ik,
-                                 _loader_data->class_loader(),
+                                 Handle(THREAD, _loader_data->class_loader()),
                                  module_handle,
                                  _protection_domain,
                                  CHECK);
@@ -5915,10 +5914,11 @@
         "Interfaces must have java.lang.Object as superclass in class file %s",
         CHECK);
     }
+    Handle loader(THREAD, _loader_data->class_loader());
     _super_klass = (const InstanceKlass*)
                        SystemDictionary::resolve_super_or_fail(_class_name,
                                                                super_class_name,
-                                                               _loader_data->class_loader(),
+                                                               loader,
                                                                _protection_domain,
                                                                true,
                                                                CHECK);
@@ -5960,6 +5960,7 @@
 
   _all_mirandas = new GrowableArray<Method*>(20);
 
+  Handle loader(THREAD, _loader_data->class_loader());
   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
                                                     &_num_miranda_methods,
                                                     _all_mirandas,
@@ -5967,7 +5968,7 @@
                                                     _methods,
                                                     _access_flags,
                                                     _major_version,
-                                                    _loader_data->class_loader(),
+                                                    loader,
                                                     _class_name,
                                                     _local_interfaces,
                                                     CHECK);
--- a/hotspot/src/share/vm/classfile/classLoader.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -1715,7 +1715,7 @@
 
   {
     MutexLocker ml(Module_lock, THREAD);
-    ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(NULL), vmSymbols::java_base(), NULL, NULL, null_cld);
+    ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(), vmSymbols::java_base(), NULL, NULL, null_cld);
     if (jb_module == NULL) {
       vm_exit_during_initialization("Unable to create ModuleEntry for " JAVA_BASE_NAME);
     }
--- a/hotspot/src/share/vm/classfile/classLoaderData.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/classLoaderData.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -522,10 +522,9 @@
 // (boot, application/system or platform) class loaders. Note, the
 // builtin loaders are not freed by a GC.
 bool ClassLoaderData::is_builtin_class_loader_data() const {
-  Handle classLoaderHandle = class_loader();
   return (is_the_null_class_loader_data() ||
-          SystemDictionary::is_system_class_loader(classLoaderHandle) ||
-          SystemDictionary::is_platform_class_loader(classLoaderHandle));
+          SystemDictionary::is_system_class_loader(class_loader()) ||
+          SystemDictionary::is_platform_class_loader(class_loader()));
 }
 
 Metaspace* ClassLoaderData::metaspace_non_null() {
@@ -627,7 +626,8 @@
 // These anonymous class loaders are to contain classes used for JSR292
 ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(oop loader, TRAPS) {
   // Add a new class loader data to the graph.
-  return ClassLoaderDataGraph::add(loader, true, THREAD);
+  Handle lh(THREAD, loader);
+  return ClassLoaderDataGraph::add(lh, true, THREAD);
 }
 
 const char* ClassLoaderData::loader_name() {
@@ -768,7 +768,7 @@
                             vmSymbols::void_string_signature(),
                             CHECK);
     assert(result.get_type() == T_OBJECT, "just checking");
-    string = (oop)result.get_jobject();
+    string = Handle(THREAD, (oop)result.get_jobject());
   }
 
   ResourceMark rm;
--- a/hotspot/src/share/vm/classfile/classLoaderData.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/classLoaderData.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -263,7 +263,7 @@
     assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
 
     // We explicitly initialize the Dependencies object at a later phase in the initialization
-    _the_null_class_loader_data = new ClassLoaderData((oop)NULL, false, Dependencies());
+    _the_null_class_loader_data = new ClassLoaderData(Handle(), false, Dependencies());
     ClassLoaderDataGraph::_head = _the_null_class_loader_data;
     assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
     if (DumpSharedSpaces) {
--- a/hotspot/src/share/vm/classfile/dictionary.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/dictionary.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -61,7 +61,7 @@
   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
 };
 
-ProtectionDomainCacheEntry* Dictionary::cache_get(oop protection_domain) {
+ProtectionDomainCacheEntry* Dictionary::cache_get(Handle protection_domain) {
   return _pd_cache_table->get(protection_domain);
 }
 
@@ -123,9 +123,9 @@
 }
 
 
-void DictionaryEntry::add_protection_domain(Dictionary* dict, oop protection_domain) {
+void DictionaryEntry::add_protection_domain(Dictionary* dict, Handle protection_domain) {
   assert_locked_or_safepoint(SystemDictionary_lock);
-  if (!contains_protection_domain(protection_domain)) {
+  if (!contains_protection_domain(protection_domain())) {
     ProtectionDomainCacheEntry* entry = dict->cache_get(protection_domain);
     ProtectionDomainEntry* new_head =
                 new ProtectionDomainEntry(entry, _pd_set);
@@ -454,7 +454,7 @@
   assert(protection_domain() != NULL,
          "real protection domain should be present");
 
-  entry->add_protection_domain(this, protection_domain());
+  entry->add_protection_domain(this, protection_domain);
 
   assert(entry->contains_protection_domain(protection_domain()),
          "now protection domain should be present");
@@ -505,11 +505,12 @@
 }
 
 
-unsigned int ProtectionDomainCacheTable::compute_hash(oop protection_domain) {
+unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) {
+  // Identity hash can safepoint, so keep protection domain in a Handle.
   return (unsigned int)(protection_domain->identity_hash());
 }
 
-int ProtectionDomainCacheTable::index_for(oop protection_domain) {
+int ProtectionDomainCacheTable::index_for(Handle protection_domain) {
   return hash_to_index(compute_hash(protection_domain));
 }
 
@@ -619,7 +620,7 @@
   }
 }
 
-ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) {
+ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) {
   unsigned int hash = compute_hash(protection_domain);
   int index = hash_to_index(hash);
 
@@ -630,9 +631,9 @@
   return entry;
 }
 
-ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, oop protection_domain) {
+ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) {
   for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
-    if (e->protection_domain() == protection_domain) {
+    if (e->protection_domain() == protection_domain()) {
       return e;
     }
   }
@@ -640,7 +641,7 @@
   return NULL;
 }
 
-ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, oop protection_domain) {
+ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, Handle protection_domain) {
   assert_locked_or_safepoint(SystemDictionary_lock);
   assert(index == index_for(protection_domain), "incorrect index?");
   assert(find_entry(index, protection_domain) == NULL, "no double entry");
@@ -651,7 +652,7 @@
 }
 
 void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) {
-  unsigned int hash = compute_hash(to_delete->protection_domain());
+  unsigned int hash = compute_hash(Handle(Thread::current(), to_delete->protection_domain()));
   int index = hash_to_index(hash);
 
   ProtectionDomainCacheEntry** p = bucket_addr(index);
@@ -731,7 +732,6 @@
 
 void Dictionary::print(bool details) {
   ResourceMark rm;
-  HandleMark   hm;
 
   if (details) {
     tty->print_cr("Java system dictionary (table_size=%d, classes=%d)",
@@ -777,7 +777,6 @@
 void Dictionary::printPerformanceInfoDetails() {
   if (log_is_enabled(Info, hashtables)) {
     ResourceMark rm;
-    HandleMark   hm;
 
     log_info(hashtables)(" ");
     log_info(hashtables)("Java system dictionary (table_size=%d, classes=%d)",
--- a/hotspot/src/share/vm/classfile/dictionary.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/dictionary.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -128,7 +128,7 @@
   // Sharing support
   void reorder_dictionary();
 
-  ProtectionDomainCacheEntry* cache_get(oop protection_domain);
+  ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
 
   void print(bool details = true);
 #ifdef ASSERT
@@ -194,23 +194,23 @@
     return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
   }
 
-  ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
-    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
+  ProtectionDomainCacheEntry* new_entry(unsigned int hash, Handle protection_domain) {
+    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain());
     entry->init();
     return entry;
   }
 
-  static unsigned int compute_hash(oop protection_domain);
+  static unsigned int compute_hash(Handle protection_domain);
 
-  int index_for(oop protection_domain);
-  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
-  ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
+  int index_for(Handle protection_domain);
+  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, Handle protection_domain);
+  ProtectionDomainCacheEntry* find_entry(int index, Handle protection_domain);
 
 public:
 
   ProtectionDomainCacheTable(int table_size);
 
-  ProtectionDomainCacheEntry* get(oop protection_domain);
+  ProtectionDomainCacheEntry* get(Handle protection_domain);
   void free(ProtectionDomainCacheEntry* entry);
 
   void unlink(BoolObjectClosure* cl);
@@ -275,7 +275,7 @@
   // Tells whether a protection is in the approved set.
   bool contains_protection_domain(oop protection_domain) const;
   // Adds a protection domain to the approved set.
-  void add_protection_domain(Dictionary* dict, oop protection_domain);
+  void add_protection_domain(Dictionary* dict, Handle protection_domain);
 
   Klass* klass() const { return (Klass*)literal(); }
   Klass** klass_addr() { return (Klass**)literal_addr(); }
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -514,11 +514,10 @@
   return result;
 }
 
-Symbol* java_lang_String::as_symbol(Handle java_string, TRAPS) {
-  oop          obj    = java_string();
-  typeArrayOop value  = java_lang_String::value(obj);
-  int          length = java_lang_String::length(obj);
-  bool      is_latin1 = java_lang_String::is_latin1(obj);
+Symbol* java_lang_String::as_symbol(oop java_string, TRAPS) {
+  typeArrayOop value  = java_lang_String::value(java_string);
+  int          length = java_lang_String::length(java_string);
+  bool      is_latin1 = java_lang_String::is_latin1(java_string);
   if (!is_latin1) {
     jchar* base = (length == 0) ? NULL : value->char_at_addr(0);
     Symbol* sym = SymbolTable::lookup_unicode(base, length, THREAD);
@@ -753,7 +752,7 @@
       }
     }
   }
-  create_mirror(k, Handle(NULL), Handle(NULL), Handle(NULL), CHECK);
+  create_mirror(k, Handle(), Handle(), Handle(), CHECK);
 }
 
 void java_lang_Class::initialize_mirror_fields(KlassHandle k,
@@ -828,7 +827,8 @@
   // the mirror.
   if (SystemDictionary::Class_klass_loaded()) {
     // Allocate mirror (java.lang.Class instance)
-    Handle mirror = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
+    oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
+    Handle mirror(THREAD, mirror_oop);
 
     // Setup indirection from mirror->klass
     if (!k.is_null()) {
@@ -842,7 +842,7 @@
 
     // It might also have a component mirror.  This mirror must already exist.
     if (k->is_array_klass()) {
-      Handle comp_mirror;
+      oop comp_mirror;
       if (k->is_typeArray_klass()) {
         BasicType type = TypeArrayKlass::cast(k())->element_type();
         comp_mirror = Universe::java_mirror(type);
@@ -852,12 +852,12 @@
         assert(element_klass != NULL, "Must have an element klass");
         comp_mirror = element_klass->java_mirror();
       }
-      assert(comp_mirror.not_null(), "must have a mirror");
+      assert(comp_mirror != NULL, "must have a mirror");
 
       // Two-way link between the array klass and its component mirror:
       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
-      set_component_mirror(mirror(), comp_mirror());
-      set_array_klass(comp_mirror(), k());
+      set_component_mirror(mirror(), comp_mirror);
+      set_array_klass(comp_mirror, k());
     } else {
       assert(k->is_instance_klass(), "Must be");
 
@@ -1518,7 +1518,7 @@
   throwable->int_field_put(depth_offset, value);
 }
 
-oop java_lang_Throwable::message(Handle throwable) {
+oop java_lang_Throwable::message(oop throwable) {
   return throwable->obj_field(detailMessage_offset);
 }
 
@@ -1547,7 +1547,7 @@
 }
 
 
-void java_lang_Throwable::print(Handle throwable, outputStream* st) {
+void java_lang_Throwable::print(oop throwable, outputStream* st) {
   ResourceMark rm;
   Klass* k = throwable->klass();
   assert(k != NULL, "just checking");
@@ -1619,11 +1619,11 @@
   // constructor for new backtrace
   BacktraceBuilder(TRAPS): _methods(NULL), _bcis(NULL), _head(NULL), _mirrors(NULL), _names(NULL) {
     expand(CHECK);
-    _backtrace = _head;
+    _backtrace = Handle(THREAD, _head);
     _index = 0;
   }
 
-  BacktraceBuilder(objArrayHandle backtrace) {
+  BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
     _methods = get_methods(backtrace);
     _bcis = get_bcis(backtrace);
     _mirrors = get_mirrors(backtrace);
@@ -1634,7 +1634,8 @@
            "method and source information arrays should match");
 
     // head is the preallocated backtrace
-    _backtrace = _head = backtrace();
+    _head = backtrace();
+    _backtrace = Handle(thread, _head);
     _index = 0;
   }
 
@@ -1840,7 +1841,7 @@
 }
 
 void java_lang_Throwable::print_stack_element(outputStream *st, const methodHandle& method, int bci) {
-  Handle mirror = method->method_holder()->java_mirror();
+  Handle mirror (Thread::current(),  method->method_holder()->java_mirror());
   int method_id = method->orig_method_idnum();
   int version = method->constants()->version();
   print_stack_element_to_stream(st, mirror, method_id, version, bci, method->name());
@@ -1852,7 +1853,7 @@
  */
 void java_lang_Throwable::print_stack_trace(Handle throwable, outputStream* st) {
   // First, print the message.
-  print(throwable, st);
+  print(throwable(), st);
   st->cr();
 
   // Now print the stack trace.
@@ -1887,7 +1888,7 @@
         throwable = Handle(THREAD, (oop) cause.get_jobject());
         if (throwable.not_null()) {
           st->print("Caused by: ");
-          print(throwable, st);
+          print(throwable(), st);
           st->cr();
         }
       }
@@ -2091,7 +2092,7 @@
   ResourceMark rm(THREAD);
   vframeStream st(THREAD);
 
-  BacktraceBuilder bt(backtrace);
+  BacktraceBuilder bt(THREAD, backtrace);
 
   // Unlike fill_in_stack_trace we do not skip fillInStackTrace or throwable init
   // methods as preallocated errors aren't created by "java" code.
@@ -2230,7 +2231,7 @@
 
 void java_lang_StackFrameInfo::set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci) {
   // set Method* or mid/cpref
-  oop mname = stackFrame->obj_field(_memberName_offset);
+  Handle mname(Thread::current(), stackFrame->obj_field(_memberName_offset));
   InstanceKlass* ik = method->method_holder();
   CallInfo info(method(), ik);
   MethodHandles::init_method_MemberName(mname, info);
@@ -3958,7 +3959,6 @@
 
 void JavaClasses::check_offsets() {
   bool valid = true;
-  HandleMark hm;
 
 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
   valid &= check_offset(klass_name, cpp_klass_name :: field_name ## _offset, #field_name, field_sig)
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -164,7 +164,7 @@
   static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
 
   // Conversion
-  static Symbol* as_symbol(Handle java_string, TRAPS);
+  static Symbol* as_symbol(oop java_string, TRAPS);
   static Symbol* as_symbol_or_null(oop java_string);
 
   // Testers
@@ -494,7 +494,7 @@
   static int get_backtrace_offset() { return backtrace_offset;}
   static int get_detailMessage_offset() { return detailMessage_offset;}
   // Message
-  static oop message(Handle throwable);
+  static oop message(oop throwable);
   static void set_message(oop throwable, oop value);
   static Symbol* detail_message(oop throwable);
   static void print_stack_element(outputStream *st, const methodHandle& method, int bci);
@@ -512,7 +512,7 @@
   // Programmatic access to stack trace
   static void get_stack_trace_elements(Handle throwable, objArrayHandle stack_trace, TRAPS);
   // Printing
-  static void print(Handle throwable, outputStream* st);
+  static void print(oop throwable, outputStream* st);
   static void print_stack_trace(Handle throwable, outputStream* st);
   static void java_printStackTrace(Handle throwable, TRAPS);
   // Debugging
--- a/hotspot/src/share/vm/classfile/moduleEntry.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/moduleEntry.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -81,7 +81,7 @@
 
 // Returns the shared ProtectionDomain
 Handle ModuleEntry::shared_protection_domain() {
-  return Handle(JNIHandles::resolve(_pd));
+  return Handle(Thread::current(), JNIHandles::resolve(_pd));
 }
 
 // Set the shared ProtectionDomain atomically
@@ -269,12 +269,12 @@
     // For the boot loader, the java.lang.reflect.Module for the unnamed module
     // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
     // this point initially create the ModuleEntry for the unnamed module.
-    _unnamed_module = new_entry(0, Handle(NULL), NULL, NULL, NULL, loader_data);
+    _unnamed_module = new_entry(0, Handle(), NULL, NULL, NULL, loader_data);
   } else {
     // For all other class loaders the java.lang.reflect.Module for their
     // corresponding unnamed module can be found in the java.lang.ClassLoader object.
     oop module = java_lang_ClassLoader::unnamedModule(loader_data->class_loader());
-    _unnamed_module = new_entry(0, Handle(module), NULL, NULL, NULL, loader_data);
+    _unnamed_module = new_entry(0, Handle(Thread::current(), module), NULL, NULL, NULL, loader_data);
 
     // Store pointer to the ModuleEntry in the unnamed module's java.lang.reflect.Module
     // object.
--- a/hotspot/src/share/vm/classfile/modules.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2016, 2017, 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
@@ -198,7 +198,7 @@
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
               "Class loader must be the boot class loader");
   }
-  Handle h_loader = Handle(THREAD, loader);
+  Handle h_loader(THREAD, loader);
 
   // Ensure the boot loader's PackageEntryTable has been created
   PackageEntryTable* package_table = get_package_entry_table(h_loader, CHECK);
@@ -320,7 +320,7 @@
 
     // Only modules defined to either the boot or platform class loader, can define a "java/" package.
     if (!h_loader.is_null() &&
-        !SystemDictionary::is_platform_class_loader(h_loader) &&
+        !SystemDictionary::is_platform_class_loader(h_loader()) &&
         strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
       const char* class_loader_name = SystemDictionary::loader_name(h_loader());
       StringUtils::replace_no_expand(package_name, "/", ".");
@@ -482,7 +482,7 @@
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
               "Class loader must be the boot class loader");
   }
-  Handle h_loader = Handle(THREAD, loader);
+  Handle h_loader(THREAD, loader);
 
   log_debug(modules)("set_bootloader_unnamed_module(): recording unnamed module for boot loader");
 
--- a/hotspot/src/share/vm/classfile/stringTable.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/stringTable.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -236,6 +236,7 @@
   assert(!Universe::heap()->is_in_reserved(name),
          "proposed name of symbol must be stable");
 
+  HandleMark hm(THREAD);  // cleanup strings created
   Handle string;
   // try to reuse the string if possible
   if (!string_or_null.is_null()) {
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -160,17 +160,17 @@
 // Returns true if the passed class loader is the builtin application class loader
 // or a custom system class loader. A customer system class loader can be
 // specified via -Djava.system.class.loader.
-bool SystemDictionary::is_system_class_loader(Handle class_loader) {
-  if (class_loader.is_null()) {
+bool SystemDictionary::is_system_class_loader(oop class_loader) {
+  if (class_loader == NULL) {
     return false;
   }
   return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass() ||
-          class_loader() == _java_system_loader);
+          class_loader == _java_system_loader);
 }
 
 // Returns true if the passed class loader is the platform class loader.
-bool SystemDictionary::is_platform_class_loader(Handle class_loader) {
-  if (class_loader.is_null()) {
+bool SystemDictionary::is_platform_class_loader(oop class_loader) {
+  if (class_loader == NULL) {
     return false;
   }
   return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass());
@@ -662,6 +662,8 @@
 
   Ticks class_load_start_time = Ticks::now();
 
+  HandleMark hm(THREAD);
+
   // Fix for 4474172; see evaluation for more details
   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
   ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
@@ -1103,6 +1105,8 @@
                                              ClassFileStream* st,
                                              TRAPS) {
 
+  HandleMark hm(THREAD);
+
   // Classloaders that support parallelism, e.g. bootstrap classloader,
   // or all classloaders with UnsyncloadClass do not acquire lock here
   bool DoObjectLock = true;
@@ -1381,6 +1385,7 @@
 
     ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
     {
+      HandleMark hm(THREAD);
       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
       check_loader_lock_contention(lockObject, THREAD);
       ObjectLocker ol(lockObject, THREAD, true);
@@ -1601,6 +1606,7 @@
 
 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
 
+  HandleMark hm(THREAD);
   ClassLoaderData* loader_data = k->class_loader_data();
   Handle class_loader_h(THREAD, loader_data->class_loader());
 
@@ -2608,8 +2614,9 @@
     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
 
   int ref_kind = JVM_REF_invokeVirtual;
-  Handle name_str = StringTable::intern(name, CHECK_(empty));
-  objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
+  oop name_oop = StringTable::intern(name, CHECK_(empty));
+  Handle name_str (THREAD, name_oop);
+  objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
   assert(appendix_box->obj_at(0) == NULL, "");
 
   // This should not happen.  JDK code should take care of that.
@@ -2619,12 +2626,12 @@
 
   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
   JavaCallArguments args;
-  args.push_oop(accessing_klass()->java_mirror());
+  args.push_oop(Handle(THREAD, accessing_klass()->java_mirror()));
   args.push_int(ref_kind);
-  args.push_oop(klass()->java_mirror());
-  args.push_oop(name_str());
-  args.push_oop(method_type());
-  args.push_oop(appendix_box());
+  args.push_oop(Handle(THREAD, klass()->java_mirror()));
+  args.push_oop(name_str);
+  args.push_oop(method_type);
+  args.push_oop(appendix_box);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
                          SystemDictionary::MethodHandleNatives_klass(),
@@ -2682,7 +2689,7 @@
   }
   bool can_be_cached = true;
   int npts = ArgumentCount(signature).size();
-  objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
+  objArrayHandle pts = oopFactory::new_objArray_handle(SystemDictionary::Class_klass(), npts, CHECK_(empty));
   int arg = 0;
   Handle rt; // the return type from the signature
   ResourceMark rm(THREAD);
@@ -2725,7 +2732,7 @@
 
   // call java.lang.invoke.MethodHandleNatives::findMethodHandleType(Class rt, Class[] pts) -> MethodType
   JavaCallArguments args(Handle(THREAD, rt()));
-  args.push_oop(pts());
+  args.push_oop(pts);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
                          SystemDictionary::MethodHandleNatives_klass(),
@@ -2768,7 +2775,8 @@
     ResourceMark rm(THREAD);
     SignatureStream ss(signature, false);
     if (!ss.is_done()) {
-      oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(),
+      oop mirror = ss.as_java_mirror(Handle(THREAD, caller->class_loader()),
+                                     Handle(THREAD, caller->protection_domain()),
                                      SignatureStream::NCDFError, CHECK_(empty));
       type = Handle(THREAD, mirror);
       ss.next();
@@ -2781,11 +2789,11 @@
 
   // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
   JavaCallArguments args;
-  args.push_oop(caller->java_mirror());  // the referring class
+  args.push_oop(Handle(THREAD, caller->java_mirror()));  // the referring class
   args.push_int(ref_kind);
-  args.push_oop(callee->java_mirror());  // the target class
-  args.push_oop(name());
-  args.push_oop(type());
+  args.push_oop(Handle(THREAD, callee->java_mirror()));  // the target class
+  args.push_oop(name);
+  args.push_oop(type);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
                          SystemDictionary::MethodHandleNatives_klass(),
@@ -2832,16 +2840,16 @@
     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty);
   }
 
-  objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
+  objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
   assert(appendix_box->obj_at(0) == NULL, "");
 
   // call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, bsm, name, mtype, info, &appendix)
   JavaCallArguments args;
-  args.push_oop(caller->java_mirror());
-  args.push_oop(bsm());
-  args.push_oop(method_name());
-  args.push_oop(method_type());
-  args.push_oop(info());
+  args.push_oop(Handle(THREAD, caller->java_mirror()));
+  args.push_oop(bsm);
+  args.push_oop(method_name);
+  args.push_oop(method_type);
+  args.push_oop(info);
   args.push_oop(appendix_box);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
--- a/hotspot/src/share/vm/classfile/systemDictionary.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/systemDictionary.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -657,8 +657,8 @@
   static instanceKlassHandle load_shared_class(Symbol* class_name,
                                                Handle class_loader,
                                                TRAPS);
-  static bool is_system_class_loader(Handle class_loader);
-  static bool is_platform_class_loader(Handle class_loader);
+  static bool is_system_class_loader(oop class_loader);
+  static bool is_platform_class_loader(oop class_loader);
 
 protected:
   static Klass* find_shared_class(Symbol* class_name);
--- a/hotspot/src/share/vm/classfile/verificationType.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/verificationType.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -44,6 +44,7 @@
 
 bool VerificationType::resolve_and_check_assignability(instanceKlassHandle klass, Symbol* name,
          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) {
+  HandleMark hm(THREAD);
   Klass* obj = SystemDictionary::resolve_or_fail(
       name, Handle(THREAD, klass->class_loader()),
       Handle(THREAD, klass->protection_domain()), true, CHECK_false);
--- a/hotspot/src/share/vm/classfile/verifier.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/classfile/verifier.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -126,7 +126,7 @@
 }
 
 bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
-  HandleMark hm;
+  HandleMark hm(THREAD);
   ResourceMark rm(THREAD);
 
   // Eagerly allocate the identity hash code for a klass. This is a fallout
@@ -1997,6 +1997,7 @@
 }
 
 Klass* ClassVerifier::load_class(Symbol* name, TRAPS) {
+  HandleMark hm(THREAD);
   // Get current loader and protection domain first.
   oop loader = current_class()->class_loader();
   oop protection_domain = current_class()->protection_domain();
--- a/hotspot/src/share/vm/code/codeBlob.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/code/codeBlob.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -209,7 +209,6 @@
 }
 
 void CodeBlob::print_code() {
-  HandleMark hm;
   ResourceMark m;
   Disassembler::decode(this, tty);
 }
--- a/hotspot/src/share/vm/code/codeCache.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1309,6 +1309,8 @@
 }
 
 // A CodeHeap is full. Print out warning and report event.
+PRAGMA_DIAG_PUSH
+PRAGMA_FORMAT_NONLITERAL_IGNORED
 void CodeCache::report_codemem_full(int code_blob_type, bool print) {
   // Get nmethod heap for the given CodeBlobType and build CodeCacheFull event
   CodeHeap* heap = get_code_heap(code_blob_type);
@@ -1317,11 +1319,27 @@
   if ((heap->full_count() == 0) || print) {
     // Not yet reported for this heap, report
     if (SegmentedCodeCache) {
-      warning("%s is full. Compiler has been disabled.", get_code_heap_name(code_blob_type));
-      warning("Try increasing the code heap size using -XX:%s=", get_code_heap_flag_name(code_blob_type));
+      ResourceMark rm;
+      stringStream msg1_stream, msg2_stream;
+      msg1_stream.print("%s is full. Compiler has been disabled.",
+                        get_code_heap_name(code_blob_type));
+      msg2_stream.print("Try increasing the code heap size using -XX:%s=",
+                 get_code_heap_flag_name(code_blob_type));
+      const char *msg1 = msg1_stream.as_string();
+      const char *msg2 = msg2_stream.as_string();
+
+      log_warning(codecache)(msg1);
+      log_warning(codecache)(msg2);
+      warning(msg1);
+      warning(msg2);
     } else {
-      warning("CodeCache is full. Compiler has been disabled.");
-      warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
+      const char *msg1 = "CodeCache is full. Compiler has been disabled.";
+      const char *msg2 = "Try increasing the code cache size using -XX:ReservedCodeCacheSize=";
+
+      log_warning(codecache)(msg1);
+      log_warning(codecache)(msg2);
+      warning(msg1);
+      warning(msg2);
     }
     ResourceMark rm;
     stringStream s;
@@ -1350,6 +1368,7 @@
     event.commit();
   }
 }
+PRAGMA_DIAG_POP
 
 void CodeCache::print_memory_overhead() {
   size_t wasted_bytes = 0;
--- a/hotspot/src/share/vm/code/debugInfo.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/code/debugInfo.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -224,7 +224,7 @@
 // ConstantOopReadValue
 
 ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
-  _value = Handle(stream->read_oop());
+  _value = Handle(Thread::current(), stream->read_oop());
   assert(_value() == NULL ||
          Universe::heap()->is_in_reserved(_value()), "Should be in heap");
 }
--- a/hotspot/src/share/vm/code/debugInfo.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/code/debugInfo.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -30,6 +30,7 @@
 #include "code/nmethod.hpp"
 #include "code/oopRecorder.hpp"
 #include "runtime/stackValue.hpp"
+#include "runtime/thread.hpp"
 #include "utilities/growableArray.hpp"
 
 // Classes used for serializing debugging information.
@@ -127,7 +128,7 @@
   Handle                      value() const             { return _value; }
   bool                        is_visited() const        { return _visited; }
 
-  void                        set_value(oop value)      { _value = Handle(value); }
+  void                        set_value(oop value)      { _value = Handle(Thread::current(), value); }
   void                        set_visited(bool visited) { _visited = false; }
 
   // Serialization of debugging information
--- a/hotspot/src/share/vm/code/dependencies.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/code/dependencies.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, 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
@@ -714,7 +714,8 @@
   if (xtty == NULL) {
     return;
   }
-  ResourceMark rm;
+  Thread* thread = Thread::current();
+  HandleMark rm(thread);
   ttyLocker ttyl;
   int ctxkj = dep_context_arg(dept);  // -1 if no context arg
   if (witness != NULL) {
@@ -732,14 +733,14 @@
     DepArgument arg = args->at(j);
     if (j == 1) {
       if (arg.is_oop()) {
-        xtty->object("x", arg.oop_value());
+        xtty->object("x", Handle(thread, arg.oop_value()));
       } else {
         xtty->object("x", arg.metadata_value());
       }
     } else {
       char xn[10]; sprintf(xn, "x%d", j);
       if (arg.is_oop()) {
-        xtty->object(xn, arg.oop_value());
+        xtty->object(xn, Handle(thread, arg.oop_value()));
       } else {
         xtty->object(xn, arg.metadata_value());
       }
--- a/hotspot/src/share/vm/code/nmethod.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/code/nmethod.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1134,8 +1134,11 @@
       xtty->end_elem();
     }
   }
+
+  const char *state_msg = _state == zombie ? "made zombie" : "made not entrant";
+  CompileTask::print_ul(this, state_msg);
   if (PrintCompilation && _state != unloaded) {
-    print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
+    print_on(tty, state_msg);
   }
 }
 
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1765,6 +1765,7 @@
 // Compile a method.
 //
 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
+  task->print_ul();
   if (PrintCompilation) {
     ResourceMark rm;
     task->print_tty();
--- a/hotspot/src/share/vm/compiler/compileTask.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/compiler/compileTask.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -86,9 +86,10 @@
                              bool is_blocking) {
   assert(!_lock->is_locked(), "bad locking");
 
+  Thread* thread = Thread::current();
   _compile_id = compile_id;
   _method = method();
-  _method_holder = JNIHandles::make_global(method->method_holder()->klass_holder());
+  _method_holder = JNIHandles::make_global(Handle(thread, method->method_holder()->klass_holder()));
   _osr_bci = osr_bci;
   _is_blocking = is_blocking;
   JVMCI_ONLY(_has_waiter = CompileBroker::compiler(comp_level)->is_jvmci();)
@@ -115,7 +116,7 @@
       } else {
         _hot_method = hot_method();
         // only add loader or mirror if different from _method_holder
-        _hot_method_holder = JNIHandles::make_global(hot_method->method_holder()->klass_holder());
+        _hot_method_holder = JNIHandles::make_global(Handle(thread, hot_method->method_holder()->klass_holder()));
       }
     }
   }
--- a/hotspot/src/share/vm/compiler/compileTask.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/compiler/compileTask.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -180,11 +180,27 @@
 
 public:
   void         print(outputStream* st = tty, const char* msg = NULL, bool short_form = false, bool cr = true);
+  void         print_ul(const char* msg = NULL){
+    Log(jit, compilation) log;
+    if (log.is_debug()) {
+      print(log.debug_stream(), msg, /* short form */ true, /* cr */ true);
+    }
+  }
   static void  print(outputStream* st, const nmethod* nm, const char* msg = NULL, bool short_form = false, bool cr = true) {
     print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
                            nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
                            msg, short_form, cr);
   }
+  static void  print_ul(const nmethod* nm, const char* msg = NULL) {
+    Log(jit, compilation) log;
+    if (log.is_debug()) {
+      print_impl(log.debug_stream(), nm->method(), nm->compile_id(),
+                 nm->comp_level(), nm->is_osr_method(),
+                 nm->is_osr_method() ? nm->osr_entry_bci() : -1,
+                 /*is_blocking*/ false,
+                 msg, /* short form */ true, /* cr */ true);
+    }
+  }
 
   static void  print_inline_indent(int inline_level, outputStream* st = tty);
 
@@ -206,6 +222,12 @@
   static void print_inlining_tty(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
     print_inlining_inner(tty, method, inline_level, bci, msg);
   }
+  static void print_inlining_ul(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
+    Log(jit, inlining) log;
+    if (log.is_debug()) {
+      print_inlining_inner(log.debug_stream(), method, inline_level, bci, msg);
+    }
+  }
 };
 
 #endif // SHARE_VM_COMPILER_COMPILETASK_HPP
--- a/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -59,7 +59,7 @@
     THROW_NULL(vmSymbols::java_lang_NullPointerException());
   }
 
-  Handle reg = code_Location::reg(location);
+  Handle reg(THREAD, code_Location::reg(location));
   jint offset = code_Location::offset(location);
 
   if (reg.not_null()) {
@@ -95,7 +95,7 @@
 
 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo
 OopMap* CodeInstaller::create_oop_map(Handle debug_info, TRAPS) {
-  Handle reference_map = DebugInfo::referenceMap(debug_info);
+  Handle reference_map(THREAD, DebugInfo::referenceMap(debug_info));
   if (reference_map.is_null()) {
     THROW_NULL(vmSymbols::java_lang_NullPointerException());
   }
@@ -106,9 +106,9 @@
     _has_wide_vector = true;
   }
   OopMap* map = new OopMap(_total_frame_size, _parameter_count);
-  objArrayHandle objects = HotSpotReferenceMap::objects(reference_map);
-  objArrayHandle derivedBase = HotSpotReferenceMap::derivedBase(reference_map);
-  typeArrayHandle sizeInBytes = HotSpotReferenceMap::sizeInBytes(reference_map);
+  objArrayHandle objects(THREAD, HotSpotReferenceMap::objects(reference_map));
+  objArrayHandle derivedBase(THREAD, HotSpotReferenceMap::derivedBase(reference_map));
+  typeArrayHandle sizeInBytes(THREAD, HotSpotReferenceMap::sizeInBytes(reference_map));
   if (objects.is_null() || derivedBase.is_null() || sizeInBytes.is_null()) {
     THROW_NULL(vmSymbols::java_lang_NullPointerException());
   }
@@ -116,8 +116,8 @@
     JVMCI_ERROR_NULL("arrays in reference map have different sizes: %d %d %d", objects->length(), derivedBase->length(), sizeInBytes->length());
   }
   for (int i = 0; i < objects->length(); i++) {
-    Handle location = objects->obj_at(i);
-    Handle baseLocation = derivedBase->obj_at(i);
+    Handle location(THREAD, objects->obj_at(i));
+    Handle baseLocation(THREAD, derivedBase->obj_at(i));
     int bytes = sizeInBytes->int_at(i);
 
     VMReg vmReg = getVMRegFromLocation(location, _total_frame_size, CHECK_NULL);
@@ -149,12 +149,12 @@
     }
   }
 
-  Handle callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info);
+  Handle callee_save_info(THREAD, (oop) DebugInfo::calleeSaveInfo(debug_info));
   if (callee_save_info.not_null()) {
-    objArrayHandle registers = RegisterSaveLayout::registers(callee_save_info);
-    typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info);
+    objArrayHandle registers(THREAD, RegisterSaveLayout::registers(callee_save_info));
+    typeArrayHandle slots(THREAD, RegisterSaveLayout::slots(callee_save_info));
     for (jint i = 0; i < slots->length(); i++) {
-      Handle jvmci_reg = registers->obj_at(i);
+      Handle jvmci_reg (THREAD, registers->obj_at(i));
       jint jvmci_reg_number = code_Register::number(jvmci_reg);
       VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL);
       // HotSpot stack slots are 4 bytes
@@ -279,9 +279,9 @@
 }
 #endif
 
-Location::Type CodeInstaller::get_oop_type(Handle value) {
-  Handle valueKind = Value::valueKind(value);
-  Handle platformKind = ValueKind::platformKind(valueKind);
+Location::Type CodeInstaller::get_oop_type(Thread* thread, Handle value) {
+  Handle valueKind(thread, Value::valueKind(value));
+  Handle platformKind(thread, ValueKind::platformKind(valueKind));
 
   if (platformKind == word_kind()) {
     return Location::oop;
@@ -300,13 +300,13 @@
     }
     return _illegal_value;
   } else if (value->is_a(RegisterValue::klass())) {
-    Handle reg = RegisterValue::reg(value);
+    Handle reg(THREAD, RegisterValue::reg(value));
     jint number = code_Register::number(reg);
     VMReg hotspotRegister = get_hotspot_reg(number, CHECK_NULL);
     if (is_general_purpose_reg(hotspotRegister)) {
       Location::Type locationType;
       if (type == T_OBJECT) {
-        locationType = get_oop_type(value);
+        locationType = get_oop_type(THREAD, value);
       } else if (type == T_LONG) {
         locationType = Location::lng;
       } else if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
@@ -343,7 +343,7 @@
 
     Location::Type locationType;
     if (type == T_OBJECT) {
-      locationType = get_oop_type(value);
+      locationType = get_oop_type(THREAD, value);
     } else if (type == T_LONG) {
       locationType = Location::lng;
     } else if (type == T_DOUBLE) {
@@ -364,7 +364,8 @@
         jlong prim = PrimitiveConstant::primitive(value);
         return new ConstantLongValue(prim);
       } else {
-        BasicType constantType = JVMCIRuntime::kindToBasicType(PrimitiveConstant::kind(value), CHECK_NULL);
+        Handle primitive_constant_kind(THREAD, PrimitiveConstant::kind(value));
+        BasicType constantType = JVMCIRuntime::kindToBasicType(primitive_constant_kind, CHECK_NULL);
         if (type != constantType) {
           JVMCI_ERROR_NULL("primitive constant type doesn't match, expected %s but got %s", basictype_to_str(type), basictype_to_str(constantType));
         }
@@ -421,18 +422,21 @@
 }
 
 void CodeInstaller::record_object_value(ObjectValue* sv, Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
-  Handle type = VirtualObject::type(value);
+  // Might want a HandleMark here.
+  Handle type(THREAD, VirtualObject::type(value));
   int id = VirtualObject::id(value);
   oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
   Klass* klass = java_lang_Class::as_Klass(javaMirror);
   bool isLongArray = klass == Universe::longArrayKlassObj();
 
-  objArrayHandle values = VirtualObject::values(value);
-  objArrayHandle slotKinds = VirtualObject::slotKinds(value);
+  objArrayHandle values(THREAD, VirtualObject::values(value));
+  objArrayHandle slotKinds(THREAD, VirtualObject::slotKinds(value));
   for (jint i = 0; i < values->length(); i++) {
+    HandleMark hm(THREAD);
     ScopeValue* cur_second = NULL;
-    Handle object = values->obj_at(i);
-    BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
+    Handle object(THREAD, values->obj_at(i));
+    Handle slot_kind (THREAD, slotKinds->obj_at(i));
+    BasicType type = JVMCIRuntime::kindToBasicType(slot_kind, CHECK);
     ScopeValue* value = get_scope_value(object, type, objects, cur_second, CHECK);
 
     if (isLongArray && cur_second == NULL) {
@@ -458,10 +462,12 @@
   }
 
   ScopeValue* second = NULL;
-  ScopeValue* owner_value = get_scope_value(StackLockValue::owner(value), T_OBJECT, objects, second, CHECK_NULL);
+  Handle stack_lock_owner(THREAD, StackLockValue::owner(value));
+  ScopeValue* owner_value = get_scope_value(stack_lock_owner, T_OBJECT, objects, second, CHECK_NULL);
   assert(second == NULL, "monitor cannot occupy two stack slots");
 
-  ScopeValue* lock_data_value = get_scope_value(StackLockValue::slot(value), T_LONG, objects, second, CHECK_NULL);
+  Handle stack_lock_slot(THREAD, StackLockValue::slot(value));
+  ScopeValue* lock_data_value = get_scope_value(stack_lock_slot, T_LONG, objects, second, CHECK_NULL);
   assert(second == lock_data_value, "monitor is LONG value that occupies two stack slots");
   assert(lock_data_value->is_location(), "invalid monitor location");
   Location lock_data_loc = ((LocationValue*)lock_data_value)->location();
@@ -476,25 +482,26 @@
 
 void CodeInstaller::initialize_dependencies(oop compiled_code, OopRecorder* recorder, TRAPS) {
   JavaThread* thread = JavaThread::current();
+  assert(THREAD == thread, "");
   CompilerThread* compilerThread = thread->is_Compiler_thread() ? thread->as_CompilerThread() : NULL;
   _oop_recorder = recorder;
   _dependencies = new Dependencies(&_arena, _oop_recorder, compilerThread != NULL ? compilerThread->log() : NULL);
-  objArrayHandle assumptions = HotSpotCompiledCode::assumptions(compiled_code);
+  objArrayHandle assumptions(THREAD, HotSpotCompiledCode::assumptions(compiled_code));
   if (!assumptions.is_null()) {
     int length = assumptions->length();
     for (int i = 0; i < length; ++i) {
-      Handle assumption = assumptions->obj_at(i);
+      Handle assumption(THREAD, assumptions->obj_at(i));
       if (!assumption.is_null()) {
         if (assumption->klass() == Assumptions_NoFinalizableSubclass::klass()) {
-          assumption_NoFinalizableSubclass(assumption);
+          assumption_NoFinalizableSubclass(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_ConcreteSubtype::klass()) {
-          assumption_ConcreteSubtype(assumption);
+          assumption_ConcreteSubtype(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_LeafType::klass()) {
-          assumption_LeafType(assumption);
+          assumption_LeafType(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_ConcreteMethod::klass()) {
-          assumption_ConcreteMethod(assumption);
+          assumption_ConcreteMethod(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_CallSiteTargetValue::klass()) {
-          assumption_CallSiteTargetValue(assumption);
+          assumption_CallSiteTargetValue(THREAD, assumption);
         } else {
           JVMCI_ERROR("unexpected Assumption subclass %s", assumption->klass()->signature_name());
         }
@@ -502,11 +509,11 @@
     }
   }
   if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
-    objArrayHandle methods = HotSpotCompiledCode::methods(compiled_code);
+    objArrayHandle methods(THREAD, HotSpotCompiledCode::methods(compiled_code));
     if (!methods.is_null()) {
       int length = methods->length();
       for (int i = 0; i < length; ++i) {
-        Handle method_handle = methods->obj_at(i);
+        Handle method_handle(THREAD, methods->obj_at(i));
         methodHandle method = getMethodFromHotSpotMethod(method_handle());
         _dependencies->assert_evol_method(method());
       }
@@ -639,7 +646,7 @@
 
 void CodeInstaller::initialize_fields(oop target, oop compiled_code, TRAPS) {
   if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) {
-    Handle hotspotJavaMethod = HotSpotCompiledNmethod::method(compiled_code);
+    Handle hotspotJavaMethod(THREAD, HotSpotCompiledNmethod::method(compiled_code));
     methodHandle method = getMethodFromHotSpotMethod(hotspotJavaMethod());
     _parameter_count = method->size_of_parameters();
     TRACE_jvmci_2("installing code for %s", method->name_and_sig_as_C_string());
@@ -728,7 +735,7 @@
 // perform data and call relocation on the CodeBuffer
 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, TRAPS) {
   HandleMark hm;
-  objArrayHandle sites = this->sites();
+  objArrayHandle sites(THREAD, this->sites());
   int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
 
   // Allocate enough space in the stub section for the static call
@@ -766,18 +773,19 @@
   _instructions->set_end(end_pc);
 
   for (int i = 0; i < data_section_patches()->length(); i++) {
-    Handle patch = data_section_patches()->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle patch(THREAD, data_section_patches()->obj_at(i));
     if (patch.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
-    Handle reference = site_DataPatch::reference(patch);
+    Handle reference(THREAD, site_DataPatch::reference(patch));
     if (reference.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
     if (!reference->is_a(site_ConstantReference::klass())) {
       JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name());
     }
-    Handle constant = site_ConstantReference::constant(reference);
+    Handle constant(THREAD, site_ConstantReference::constant(reference));
     if (constant.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
@@ -793,7 +801,7 @@
         *((void**) dest) = record_metadata_reference(_constants, dest, constant, CHECK_OK);
       }
     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
-      Handle obj = HotSpotObjectConstantImpl::object(constant);
+      Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
       jobject value = JNIHandles::make_local(obj());
       int oop_index = _oop_recorder->find_index(value);
 
@@ -812,7 +820,8 @@
   }
   jint last_pc_offset = -1;
   for (int i = 0; i < sites->length(); i++) {
-    Handle site = sites->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle site(THREAD, sites->obj_at(i));
     if (site.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
@@ -869,15 +878,15 @@
   return JVMCIEnv::ok;
 }
 
-void CodeInstaller::assumption_NoFinalizableSubclass(Handle assumption) {
-  Handle receiverType_handle = Assumptions_NoFinalizableSubclass::receiverType(assumption());
+void CodeInstaller::assumption_NoFinalizableSubclass(Thread* thread, Handle assumption) {
+  Handle receiverType_handle (thread, Assumptions_NoFinalizableSubclass::receiverType(assumption()));
   Klass* receiverType = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(receiverType_handle));
   _dependencies->assert_has_no_finalizable_subclasses(receiverType);
 }
 
-void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) {
-  Handle context_handle = Assumptions_ConcreteSubtype::context(assumption());
-  Handle subtype_handle = Assumptions_ConcreteSubtype::subtype(assumption());
+void CodeInstaller::assumption_ConcreteSubtype(Thread* thread, Handle assumption) {
+  Handle context_handle (thread, Assumptions_ConcreteSubtype::context(assumption()));
+  Handle subtype_handle (thread, Assumptions_ConcreteSubtype::subtype(assumption()));
   Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
   Klass* subtype = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(subtype_handle));
 
@@ -885,16 +894,16 @@
   _dependencies->assert_abstract_with_unique_concrete_subtype(context, subtype);
 }
 
-void CodeInstaller::assumption_LeafType(Handle assumption) {
-  Handle context_handle = Assumptions_LeafType::context(assumption());
+void CodeInstaller::assumption_LeafType(Thread* thread, Handle assumption) {
+  Handle context_handle (thread, Assumptions_LeafType::context(assumption()));
   Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
 
   _dependencies->assert_leaf_type(context);
 }
 
-void CodeInstaller::assumption_ConcreteMethod(Handle assumption) {
-  Handle impl_handle = Assumptions_ConcreteMethod::impl(assumption());
-  Handle context_handle = Assumptions_ConcreteMethod::context(assumption());
+void CodeInstaller::assumption_ConcreteMethod(Thread* thread, Handle assumption) {
+  Handle impl_handle (thread, Assumptions_ConcreteMethod::impl(assumption()));
+  Handle context_handle (thread, Assumptions_ConcreteMethod::context(assumption()));
 
   methodHandle impl = getMethodFromHotSpotMethod(impl_handle());
   Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
@@ -902,9 +911,9 @@
   _dependencies->assert_unique_concrete_method(context, impl());
 }
 
-void CodeInstaller::assumption_CallSiteTargetValue(Handle assumption) {
-  Handle callSite = Assumptions_CallSiteTargetValue::callSite(assumption());
-  Handle methodHandle = Assumptions_CallSiteTargetValue::methodHandle(assumption());
+void CodeInstaller::assumption_CallSiteTargetValue(Thread* thread, Handle assumption) {
+  Handle callSite(thread, Assumptions_CallSiteTargetValue::callSite(assumption()));
+  Handle methodHandle(thread, Assumptions_CallSiteTargetValue::methodHandle(assumption()));
 
   _dependencies->assert_call_site_target_value(callSite(), methodHandle());
 }
@@ -936,16 +945,17 @@
 }
 
 GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(Handle debug_info, TRAPS) {
-  objArrayHandle virtualObjects = DebugInfo::virtualObjectMapping(debug_info);
+  objArrayHandle virtualObjects(THREAD, DebugInfo::virtualObjectMapping(debug_info));
   if (virtualObjects.is_null()) {
     return NULL;
   }
   GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(virtualObjects->length(), virtualObjects->length(), NULL);
   // Create the unique ObjectValues
   for (int i = 0; i < virtualObjects->length(); i++) {
-    Handle value = virtualObjects->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle value(THREAD, virtualObjects->obj_at(i));
     int id = VirtualObject::id(value);
-    Handle type = VirtualObject::type(value);
+    Handle type(THREAD, VirtualObject::type(value));
     oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
     ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror)));
     if (id < 0 || id >= objects->length()) {
@@ -959,7 +969,8 @@
   // All the values which could be referenced by the VirtualObjects
   // exist, so now describe all the VirtualObjects themselves.
   for (int i = 0; i < virtualObjects->length(); i++) {
-    Handle value = virtualObjects->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle value(THREAD, virtualObjects->obj_at(i));
     int id = VirtualObject::id(value);
     record_object_value(objects->at(id)->as_ObjectValue(), value, objects, CHECK_NULL);
   }
@@ -968,7 +979,7 @@
 }
 
 void CodeInstaller::record_scope(jint pc_offset, Handle debug_info, ScopeMode scope_mode, bool return_oop, TRAPS) {
-  Handle position = DebugInfo::bytecodePosition(debug_info);
+  Handle position(THREAD, DebugInfo::bytecodePosition(debug_info));
   if (position.is_null()) {
     // Stubs do not record scope info, just oop maps
     return;
@@ -991,12 +1002,12 @@
     }
     frame = position;
   }
-  Handle caller_frame = BytecodePosition::caller(position);
+  Handle caller_frame (THREAD, BytecodePosition::caller(position));
   if (caller_frame.not_null()) {
     record_scope(pc_offset, caller_frame, scope_mode, objects, return_oop, CHECK);
   }
 
-  Handle hotspot_method = BytecodePosition::method(position);
+  Handle hotspot_method (THREAD, BytecodePosition::method(position));
   Method* method = getMethodFromHotSpotMethod(hotspot_method());
   jint bci = BytecodePosition::bci(position);
   if (bci == BytecodeFrame::BEFORE_BCI()) {
@@ -1027,8 +1038,8 @@
     jint local_count = BytecodeFrame::numLocals(frame);
     jint expression_count = BytecodeFrame::numStack(frame);
     jint monitor_count = BytecodeFrame::numLocks(frame);
-    objArrayHandle values = BytecodeFrame::values(frame);
-    objArrayHandle slotKinds = BytecodeFrame::slotKinds(frame);
+    objArrayHandle values(THREAD, BytecodeFrame::values(frame));
+    objArrayHandle slotKinds(THREAD, BytecodeFrame::slotKinds(frame));
 
     if (values.is_null() || slotKinds.is_null()) {
       THROW(vmSymbols::java_lang_NullPointerException());
@@ -1048,17 +1059,18 @@
     TRACE_jvmci_2("%d locals %d expressions, %d monitors", local_count, expression_count, monitor_count);
 
     for (jint i = 0; i < values->length(); i++) {
+      HandleMark hm(THREAD);
       ScopeValue* second = NULL;
-      Handle value = values->obj_at(i);
+      Handle value(THREAD, values->obj_at(i));
       if (i < local_count) {
-        BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
+        BasicType type = JVMCIRuntime::kindToBasicType(Handle(THREAD, slotKinds->obj_at(i)), CHECK);
         ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
         if (second != NULL) {
           locals->append(second);
         }
         locals->append(first);
       } else if (i < local_count + expression_count) {
-        BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
+        BasicType type = JVMCIRuntime::kindToBasicType(Handle(THREAD, slotKinds->obj_at(i)), CHECK);
         ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
         if (second != NULL) {
           expressions->append(second);
@@ -1088,7 +1100,7 @@
 }
 
 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle debug_info = site_Infopoint::debugInfo(site);
+  Handle debug_info (THREAD, site_Infopoint::debugInfo(site));
   if (debug_info.is_null()) {
     JVMCI_ERROR("debug info expected at safepoint at %i", pc_offset);
   }
@@ -1102,7 +1114,7 @@
 }
 
 void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle debug_info = site_Infopoint::debugInfo(site);
+  Handle debug_info (THREAD, site_Infopoint::debugInfo(site));
   if (debug_info.is_null()) {
     JVMCI_ERROR("debug info expected at infopoint at %i", pc_offset);
   }
@@ -1117,7 +1129,7 @@
 }
 
 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle target = site_Call::target(site);
+  Handle target(THREAD, site_Call::target(site));
   InstanceKlass* target_klass = InstanceKlass::cast(target->klass());
 
   Handle hotspot_method; // JavaMethod
@@ -1129,7 +1141,7 @@
     hotspot_method = target;
   }
 
-  Handle debug_info = site_Call::debugInfo(site);
+  Handle debug_info (THREAD, site_Call::debugInfo(site));
 
   assert(hotspot_method.not_null() ^ foreign_call.not_null(), "Call site needs exactly one type");
 
@@ -1177,11 +1189,11 @@
 }
 
 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle reference = site_DataPatch::reference(site);
+  Handle reference(THREAD, site_DataPatch::reference(site));
   if (reference.is_null()) {
     THROW(vmSymbols::java_lang_NullPointerException());
   } else if (reference->is_a(site_ConstantReference::klass())) {
-    Handle constant = site_ConstantReference::constant(reference);
+    Handle constant(THREAD, site_ConstantReference::constant(reference));
     if (constant.is_null()) {
       THROW(vmSymbols::java_lang_NullPointerException());
     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
@@ -1213,7 +1225,7 @@
 }
 
 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle id_obj = site_Mark::id(site);
+  Handle id_obj (THREAD, site_Mark::id(site));
 
   if (id_obj.not_null()) {
     if (!java_lang_boxing_object::is_instance(id_obj(), T_INT)) {
--- a/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -211,7 +211,7 @@
   const OopMapSet* oopMapSet() const { return _debug_recorder->_oopmaps; }
 
 protected:
-  Location::Type get_oop_type(Handle value);
+  Location::Type get_oop_type(Thread* thread, Handle value);
   ScopeValue* get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS);
   MonitorValue* get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS);
 
@@ -229,11 +229,11 @@
   // perform data and call relocation on the CodeBuffer
   JVMCIEnv::CodeInstallResult initialize_buffer(CodeBuffer& buffer, TRAPS);
 
-  void assumption_NoFinalizableSubclass(Handle assumption);
-  void assumption_ConcreteSubtype(Handle assumption);
-  void assumption_LeafType(Handle assumption);
-  void assumption_ConcreteMethod(Handle assumption);
-  void assumption_CallSiteTargetValue(Handle assumption);
+  void assumption_NoFinalizableSubclass(Thread* thread, Handle assumption);
+  void assumption_ConcreteSubtype(Thread* thread, Handle assumption);
+  void assumption_LeafType(Thread* thread, Handle assumption);
+  void assumption_ConcreteMethod(Thread* thread, Handle assumption);
+  void assumption_CallSiteTargetValue(Thread* thread, Handle assumption);
 
   void site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS);
   void site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS);
--- a/hotspot/src/share/vm/jvmci/jvmciCompiler.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciCompiler.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -148,7 +148,7 @@
   if (!HAS_PENDING_EXCEPTION) {
     JavaCallArguments args;
     args.push_oop(receiver);
-    args.push_oop((oop)method_result.get_jobject());
+    args.push_oop(Handle(THREAD, (oop)method_result.get_jobject()));
     args.push_int(entry_bci);
     args.push_long((jlong) (address) env);
     args.push_int(env->task()->compile_id());
@@ -202,7 +202,7 @@
   return level;
 }
 
-void JVMCICompiler::exit_on_pending_exception(Handle exception, const char* message) {
+void JVMCICompiler::exit_on_pending_exception(oop exception, const char* message) {
   JavaThread* THREAD = JavaThread::current();
   CLEAR_PENDING_EXCEPTION;
 
@@ -210,7 +210,8 @@
   if (!report_error && Atomic::cmpxchg(1, &report_error, 0) == 0) {
     // Only report an error once
     tty->print_raw_cr(message);
-    java_lang_Throwable::java_printStackTrace(exception, THREAD);
+    Handle ex(THREAD, exception);
+    java_lang_Throwable::java_printStackTrace(ex, THREAD);
   } else {
     // Allow error reporting thread to print the stack trace.
     os::sleep(THREAD, 200, false);
--- a/hotspot/src/share/vm/jvmci/jvmciCompiler.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciCompiler.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -50,7 +50,7 @@
   /**
    * Exits the VM due to an unexpected exception.
    */
-  static void exit_on_pending_exception(Handle exception, const char* message);
+  static void exit_on_pending_exception(oop exception, const char* message);
 
 public:
   JVMCICompiler();
--- a/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -80,7 +80,7 @@
   if (klass() != NULL) {
     JavaValue result(T_OBJECT);
     JavaCallArguments args;
-    args.push_oop(klass->java_mirror());
+    args.push_oop(Handle(THREAD, klass->java_mirror()));
     JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedObjectTypeImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::klass_fromMetaspace_signature(), &args, CHECK_NULL);
 
     return (oop)result.get_jobject();
@@ -204,7 +204,7 @@
 }
 
 objArrayHandle CompilerToVM::initialize_intrinsics(TRAPS) {
-  objArrayHandle vmIntrinsics = oopFactory::new_objArray(VMIntrinsicMethod::klass(), (vmIntrinsics::ID_LIMIT - 1), CHECK_(objArrayHandle()));
+  objArrayHandle vmIntrinsics = oopFactory::new_objArray_handle(VMIntrinsicMethod::klass(), (vmIntrinsics::ID_LIMIT - 1), CHECK_(objArrayHandle()));
   int index = 0;
   // The intrinsics for a class are usually adjacent to each other.
   // When they are, the string for the class name can be reused.
@@ -250,8 +250,9 @@
   VMIntrinsicMethod::klass()->initialize(CHECK_NULL);
 
   int len = JVMCIVMStructs::localHotSpotVMStructs_count();
-  objArrayHandle vmFields = oopFactory::new_objArray(VMField::klass(), len, CHECK_NULL);
+  objArrayHandle vmFields = oopFactory::new_objArray_handle(VMField::klass(), len, CHECK_NULL);
   for (int i = 0; i < len ; i++) {
+    HandleMark hm(THREAD);
     VMStructEntry vmField = JVMCIVMStructs::localHotSpotVMStructs[i];
     instanceHandle vmFieldObj = InstanceKlass::cast(VMField::klass())->allocate_instance_handle(CHECK_NULL);
     size_t name_buf_len = strlen(vmField.typeName) + strlen(vmField.fieldName) + 2 /* "::" */;
@@ -290,8 +291,9 @@
   }
 
   len = JVMCIVMStructs::localHotSpotVMTypes_count();
-  objArrayHandle vmTypes = oopFactory::new_objArray(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
+  objArrayHandle vmTypes = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
   for (int i = 0; i < len ; i++) {
+    HandleMark hm(THREAD);
     VMTypeEntry vmType = JVMCIVMStructs::localHotSpotVMTypes[i];
     Handle name = java_lang_String::create_from_str(vmType.typeName, CHECK_NULL);
     BOXED_LONG(size, vmType.size);
@@ -302,9 +304,10 @@
   int ints_len = JVMCIVMStructs::localHotSpotVMIntConstants_count();
   int longs_len = JVMCIVMStructs::localHotSpotVMLongConstants_count();
   len = ints_len + longs_len;
-  objArrayHandle vmConstants = oopFactory::new_objArray(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
+  objArrayHandle vmConstants = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
   int insert = 0;
   for (int i = 0; i < ints_len ; i++) {
+    HandleMark hm(THREAD);
     VMIntConstantEntry c = JVMCIVMStructs::localHotSpotVMIntConstants[i];
     Handle name = java_lang_String::create_from_str(c.name, CHECK_NULL);
     BOXED_LONG(value, c.value);
@@ -312,6 +315,7 @@
     vmConstants->obj_at_put(insert++, value);
   }
   for (int i = 0; i < longs_len ; i++) {
+    HandleMark hm(THREAD);
     VMLongConstantEntry c = JVMCIVMStructs::localHotSpotVMLongConstants[i];
     Handle name = java_lang_String::create_from_str(c.name, CHECK_NULL);
     BOXED_LONG(value, c.value);
@@ -321,8 +325,9 @@
   assert(insert == len * 2, "must be");
 
   len = JVMCIVMStructs::localHotSpotVMAddresses_count();
-  objArrayHandle vmAddresses = oopFactory::new_objArray(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
+  objArrayHandle vmAddresses = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
   for (int i = 0; i < len ; i++) {
+    HandleMark hm(THREAD);
     VMAddressEntry a = JVMCIVMStructs::localHotSpotVMAddresses[i];
     Handle name = java_lang_String::create_from_str(a.name, CHECK_NULL);
     BOXED_LONG(value, a.value);
@@ -332,8 +337,9 @@
 
   // The last entry is the null entry.
   len = (int) Flag::numFlags - 1;
-  objArrayHandle vmFlags = oopFactory::new_objArray(VMFlag::klass(), len, CHECK_NULL);
+  objArrayHandle vmFlags = oopFactory::new_objArray_handle(VMFlag::klass(), len, CHECK_NULL);
   for (int i = 0; i < len; i++) {
+    HandleMark hm(THREAD);
     Flag* flag = &Flag::flags[i];
     instanceHandle vmFlagObj = InstanceKlass::cast(VMFlag::klass())->allocate_instance_handle(CHECK_NULL);
     Handle name = java_lang_String::create_from_str(flag->_name, CHECK_NULL);
@@ -606,21 +612,19 @@
 
 C2V_VMENTRY(jobject, lookupType, (JNIEnv*, jobject, jstring jname, jclass accessing_class, jboolean resolve))
   ResourceMark rm;
-  Handle name = JNIHandles::resolve(jname);
-  Symbol* class_name = java_lang_String::as_symbol(name, CHECK_0);
+  Handle name(THREAD, JNIHandles::resolve(jname));
+  Symbol* class_name = java_lang_String::as_symbol(name(), CHECK_0);
   if (java_lang_String::length(name()) <= 1) {
     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
   }
 
   Klass* resolved_klass = NULL;
-  Handle class_loader;
-  Handle protection_domain;
   if (JNIHandles::resolve(accessing_class) == NULL) {
     THROW_0(vmSymbols::java_lang_NullPointerException());
   }
   Klass* accessing_klass = java_lang_Class::as_Klass(JNIHandles::resolve(accessing_class));
-  class_loader = accessing_klass->class_loader();
-  protection_domain = accessing_klass->protection_domain();
+  Handle class_loader(THREAD, accessing_klass->class_loader());
+  Handle protection_domain(THREAD, accessing_klass->protection_domain());
 
   if (resolve) {
     resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_0);
@@ -656,8 +660,8 @@
       }
     }
   }
-  Handle result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
-  return JNIHandles::make_local(THREAD, result());
+  oop result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
+  return JNIHandles::make_local(THREAD, result);
 C2V_END
 
 C2V_VMENTRY(jobject, resolveConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
@@ -697,8 +701,8 @@
 C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
   Klass* resolved_klass = cp->klass_at(index, CHECK_NULL);
-  Handle klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
-  return JNIHandles::make_local(THREAD, klass());
+  oop klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
+  return JNIHandles::make_local(THREAD, klass);
 C2V_END
 
 C2V_VMENTRY(jobject, lookupKlassInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
@@ -710,13 +714,14 @@
   if (klass.is_null()) {
     symbol = cp->klass_name_at(index);
   }
-  Handle result;
+  oop result_oop;
   if (!klass.is_null()) {
-    result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
+    result_oop = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
   } else {
-    result = java_lang_String::create_from_symbol(symbol, CHECK_NULL);
+    Handle result = java_lang_String::create_from_symbol(symbol, CHECK_NULL);
+    result_oop = result();
   }
-  return JNIHandles::make_local(THREAD, result());
+  return JNIHandles::make_local(THREAD, result_oop);
 C2V_END
 
 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
@@ -838,11 +843,11 @@
 C2V_VMENTRY(jint, installCode, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject installed_code, jobject speculation_log))
   ResourceMark rm;
   HandleMark hm;
-  Handle target_handle = JNIHandles::resolve(target);
-  Handle compiled_code_handle = JNIHandles::resolve(compiled_code);
+  Handle target_handle(THREAD, JNIHandles::resolve(target));
+  Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
   CodeBlob* cb = NULL;
-  Handle installed_code_handle = JNIHandles::resolve(installed_code);
-  Handle speculation_log_handle = JNIHandles::resolve(speculation_log);
+  Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
+  Handle speculation_log_handle(THREAD, JNIHandles::resolve(speculation_log));
 
   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK_JNI_ERR);
 
@@ -900,9 +905,9 @@
   ResourceMark rm;
   HandleMark hm;
 
-  Handle target_handle = JNIHandles::resolve(target);
-  Handle compiled_code_handle = JNIHandles::resolve(compiled_code);
-  Handle metadata_handle = JNIHandles::resolve(metadata);
+  Handle target_handle(THREAD, JNIHandles::resolve(target));
+  Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
+  Handle metadata_handle(THREAD, JNIHandles::resolve(metadata));
 
   CodeMetadata code_metadata;
   CodeBlob *cb = NULL;
@@ -914,19 +919,19 @@
   }
 
   if (code_metadata.get_nr_pc_desc() > 0) {
-    typeArrayHandle pcArrayOop = oopFactory::new_byteArray(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full));
+    typeArrayHandle pcArrayOop = oopFactory::new_byteArray_handle(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full));
     memcpy(pcArrayOop->byte_at_addr(0), code_metadata.get_pc_desc(), sizeof(PcDesc) * code_metadata.get_nr_pc_desc());
     HotSpotMetaData::set_pcDescBytes(metadata_handle, pcArrayOop());
   }
 
   if (code_metadata.get_scopes_size() > 0) {
-    typeArrayHandle scopesArrayOop = oopFactory::new_byteArray(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full));
+    typeArrayHandle scopesArrayOop = oopFactory::new_byteArray_handle(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full));
     memcpy(scopesArrayOop->byte_at_addr(0), code_metadata.get_scopes_desc(), code_metadata.get_scopes_size());
     HotSpotMetaData::set_scopesDescBytes(metadata_handle, scopesArrayOop());
   }
 
   RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer();
-  typeArrayHandle relocArrayOop = oopFactory::new_byteArray((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full));
+  typeArrayHandle relocArrayOop = oopFactory::new_byteArray_handle((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full));
   if (reloc_buffer->size() > 0) {
     memcpy(relocArrayOop->byte_at_addr(0), reloc_buffer->begin(), reloc_buffer->size());
   }
@@ -937,7 +942,7 @@
     ResourceMark mark;
     ImmutableOopMapBuilder builder(oopMapSet);
     int oopmap_size = builder.heap_size();
-    typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray(oopmap_size, CHECK_(JVMCIEnv::cache_full));
+    typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray_handle(oopmap_size, CHECK_(JVMCIEnv::cache_full));
     builder.generate_into((address) oopMapArrayHandle->byte_at_addr(0));
     HotSpotMetaData::set_oopMaps(metadata_handle, oopMapArrayHandle());
   }
@@ -945,7 +950,8 @@
   AOTOopRecorder* recorder = code_metadata.get_oop_recorder();
 
   int nr_meta_strings = recorder->nr_meta_strings();
-  objArrayHandle metadataArrayHandle = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full));
+  objArrayOop metadataArray = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full));
+  objArrayHandle metadataArrayHandle(THREAD, metadataArray);
   for (int i = 0; i < nr_meta_strings; ++i) {
     const char* element = recorder->meta_element(i);
     Handle java_string = java_lang_String::create_from_str(element, CHECK_(JVMCIEnv::cache_full));
@@ -955,7 +961,7 @@
 
   ExceptionHandlerTable* handler = code_metadata.get_exception_table();
   int table_size = handler->size_in_bytes();
-  typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray(table_size, CHECK_(JVMCIEnv::cache_full));
+  typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray_handle(table_size, CHECK_(JVMCIEnv::cache_full));
 
   if (table_size > 0) {
     handler->copy_bytes_to((address) exceptionArrayOop->byte_at_addr(0));
@@ -1134,7 +1140,7 @@
 
 
 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject installed_code))
-  Handle installed_code_handle = JNIHandles::resolve(installed_code);
+  Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
   nmethod::invalidate_installed_code(installed_code_handle, CHECK);
 C2V_END
 
@@ -1189,7 +1195,7 @@
   ResourceMark rm;
 
   if (!thread->has_last_Java_frame()) return NULL;
-  Handle result = HotSpotStackFrameReference::klass()->allocate_instance(thread);
+  Handle result = HotSpotStackFrameReference::klass()->allocate_instance_handle(thread);
   HotSpotStackFrameReference::klass()->initialize(thread);
 
   StackFrameStream fst(thread);
@@ -1248,7 +1254,8 @@
               Deoptimization::reassign_fields(fst.current(), fst.register_map(), scope->objects(), realloc_failures, false);
 
               GrowableArray<ScopeValue*>* local_values = scope->locals();
-              typeArrayHandle array = oopFactory::new_boolArray(local_values->length(), thread);
+              typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), thread);
+              typeArrayHandle array(THREAD, array_oop);
               for (int i = 0; i < local_values->length(); i++) {
                 ScopeValue* value = local_values->at(i);
                 if (value->is_object()) {
@@ -1289,7 +1296,8 @@
         HotSpotStackFrameReference::set_frameNumber(result, frame_number);
 
         // initialize the locals array
-        objArrayHandle array = oopFactory::new_objectArray(locals->size(), thread);
+        objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL);
+        objArrayHandle array(THREAD, array_oop);
         for (int i = 0; i < locals->size(); i++) {
           StackValue* var = locals->at(i);
           if (var->type() == T_OBJECT) {
@@ -1341,7 +1349,7 @@
 C2V_END
 
 C2V_VMENTRY(jobject, getSignaturePolymorphicHolders, (JNIEnv*, jobject))
-  objArrayHandle holders = oopFactory::new_objArray(SystemDictionary::String_klass(), 2, CHECK_NULL);
+  objArrayHandle holders = oopFactory::new_objArray_handle(SystemDictionary::String_klass(), 2, CHECK_NULL);
   Handle mh = java_lang_String::create_from_str("Ljava/lang/invoke/MethodHandle;", CHECK_NULL);
   Handle vh = java_lang_String::create_from_str("Ljava/lang/invoke/VarHandle;", CHECK_NULL);
   holders->obj_at_put(0, mh());
@@ -1448,7 +1456,7 @@
   HotSpotStackFrameReference::set_localIsVirtual(hs_frame, NULL);
 
   // update the locals array
-  objArrayHandle array = HotSpotStackFrameReference::locals(hs_frame);
+  objArrayHandle array(THREAD, HotSpotStackFrameReference::locals(hs_frame));
   StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals();
   for (int i = 0; i < locals->size(); i++) {
     StackValue* var = locals->at(i);
@@ -1549,7 +1557,7 @@
 C2V_END
 
 C2V_VMENTRY(void, compileToBytecode, (JNIEnv*, jobject, jobject lambda_form_handle))
-  Handle lambda_form = JNIHandles::resolve_non_null(lambda_form_handle);
+  Handle lambda_form(THREAD, JNIHandles::resolve_non_null(lambda_form_handle));
   if (lambda_form->is_a(SystemDictionary::LambdaForm_klass())) {
     TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode", CHECK);
     JavaValue result(T_VOID);
--- a/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -144,11 +144,11 @@
   arrayOop _args;
   int _index;
 
-  oop next_arg(BasicType expectedType) {
+  Handle next_arg(BasicType expectedType) {
     assert(_index < _args->length(), "out of bounds");
     oop arg=((objArrayOop) (_args))->obj_at(_index++);
     assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
-    return arg;
+    return Handle(Thread::current(), arg);
   }
 
  public:
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -650,7 +650,7 @@
   } else {
     JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle()));
   }
-  return Handle((oop)result.get_jobject());
+  return Handle(THREAD, (oop)result.get_jobject());
 }
 
 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
@@ -684,7 +684,7 @@
          "compilation level adjustment out of bounds");
   _comp_level_adjustment = (CompLevelAdjustment) adjustment;
   _HotSpotJVMCIRuntime_initialized = true;
-  _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result());
+  _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result);
 }
 
 void JVMCIRuntime::initialize_JVMCI(TRAPS) {
@@ -863,9 +863,9 @@
   JavaValue result(T_INT);
   JavaCallArguments args;
   args.push_oop(receiver);
-  args.push_oop(method->method_holder()->java_mirror());
-  args.push_oop(name());
-  args.push_oop(sig());
+  args.push_oop(Handle(THREAD, method->method_holder()->java_mirror()));
+  args.push_oop(name);
+  args.push_oop(sig);
   args.push_int(is_osr);
   args.push_int(level);
   JavaCalls::call_special(&result, receiver->klass(), vmSymbols::adjustCompilationLevel_name(),
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -75,7 +75,7 @@
    */
   static Handle get_HotSpotJVMCIRuntime(TRAPS) {
     initialize_JVMCI(CHECK_(Handle()));
-    return Handle(JNIHandles::resolve_non_null(_HotSpotJVMCIRuntime_instance));
+    return Handle(THREAD, JNIHandles::resolve_non_null(_HotSpotJVMCIRuntime_instance));
   }
 
   static jobject get_HotSpotJVMCIRuntime_jobject(TRAPS) {
--- a/hotspot/src/share/vm/logging/logTag.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/logging/logTag.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -48,7 +48,9 @@
   LOG_TAG(class) \
   LOG_TAG(classhisto) \
   LOG_TAG(cleanup) \
+  LOG_TAG(codecache) \
   LOG_TAG(compaction) \
+  LOG_TAG(compilation) \
   LOG_TAG(constraints) \
   LOG_TAG(constantpool) \
   LOG_TAG(coops) \
@@ -69,7 +71,9 @@
   LOG_TAG(ihop) \
   LOG_TAG(iklass) \
   LOG_TAG(init) \
+  LOG_TAG(inlining) \
   LOG_TAG(itables) \
+  LOG_TAG(jit) \
   LOG_TAG(jni) \
   LOG_TAG(jvmti) \
   LOG_TAG(liveness) \
--- a/hotspot/src/share/vm/memory/oopFactory.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/memory/oopFactory.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -85,3 +85,13 @@
     return InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
   }
 }
+
+objArrayHandle oopFactory::new_objArray_handle(Klass* klass, int length, TRAPS) {
+  objArrayOop obj = new_objArray(klass, length, CHECK_(objArrayHandle()));
+  return objArrayHandle(THREAD, obj);
+}
+
+typeArrayHandle oopFactory::new_byteArray_handle(int length, TRAPS) {
+  typeArrayOop obj = new_byteArray(length, CHECK_(typeArrayHandle()));
+  return typeArrayHandle(THREAD, obj);
+}
--- a/hotspot/src/share/vm/memory/oopFactory.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/memory/oopFactory.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -66,6 +66,10 @@
 
   // Regular object arrays
   static objArrayOop     new_objArray(Klass* klass, int length, TRAPS);
+
+  // Helpers that return handles
+  static objArrayHandle  new_objArray_handle(Klass* klass, int length, TRAPS);
+  static typeArrayHandle new_byteArray_handle(int length, TRAPS);
 };
 
 #endif // SHARE_VM_MEMORY_OOPFACTORY_HPP
--- a/hotspot/src/share/vm/memory/universe.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/memory/universe.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -615,20 +615,22 @@
     // return default
     return default_err;
   } else {
+    Thread* THREAD = Thread::current();
+    Handle default_err_h(THREAD, default_err);
     // get the error object at the slot and set set it to NULL so that the
     // array isn't keeping it alive anymore.
-    oop exc = preallocated_out_of_memory_errors()->obj_at(next);
-    assert(exc != NULL, "slot has been used already");
+    Handle exc(THREAD, preallocated_out_of_memory_errors()->obj_at(next));
+    assert(exc() != NULL, "slot has been used already");
     preallocated_out_of_memory_errors()->obj_at_put(next, NULL);
 
     // use the message from the default error
-    oop msg = java_lang_Throwable::message(default_err);
+    oop msg = java_lang_Throwable::message(default_err_h());
     assert(msg != NULL, "no message");
-    java_lang_Throwable::set_message(exc, msg);
+    java_lang_Throwable::set_message(exc(), msg);
 
     // populate the stack trace and return it.
     java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(exc);
-    return exc;
+    return exc();
   }
 }
 
--- a/hotspot/src/share/vm/oops/arrayKlass.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/oops/arrayKlass.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -107,7 +107,7 @@
   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
          "module entry not available post " JAVA_BASE_NAME " definition");
   oop module = (module_entry != NULL) ? JNIHandles::resolve(module_entry->module()) : (oop)NULL;
-  java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(NULL), CHECK);
+  java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
 }
 
 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {
--- a/hotspot/src/share/vm/oops/cpCache.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/oops/cpCache.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -282,7 +282,7 @@
   // the lock, so that when the losing writer returns, he can use the linked
   // cache entry.
 
-  objArrayHandle resolved_references = cpool->resolved_references();
+  objArrayHandle resolved_references(Thread::current(), cpool->resolved_references());
   // Use the resolved_references() lock for this cpCache entry.
   // resolved_references are created for all classes with Invokedynamic, MethodHandle
   // or MethodType constant pool cache entries.
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -434,8 +434,9 @@
 
 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_k) {
   EXCEPTION_MARK;
-  oop init_lock = this_k->init_lock();
-  ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
+  HandleMark hm(THREAD);
+  Handle init_lock(THREAD, this_k->init_lock());
+  ObjectLocker ol(init_lock, THREAD, init_lock() != NULL);
 
   // abort if someone beat us to the initialization
   if (!this_k->is_not_initialized()) return;  // note: not equivalent to is_initialized()
@@ -469,7 +470,6 @@
 // Note: implementation moved to static method to expose the this pointer.
 void InstanceKlass::initialize(TRAPS) {
   if (this->should_be_initialized()) {
-    HandleMark hm(THREAD);
     instanceKlassHandle this_k(THREAD, this);
     initialize_impl(this_k, CHECK);
     // Note: at this point the class may be initialized
@@ -501,7 +501,6 @@
 void InstanceKlass::link_class(TRAPS) {
   assert(is_loaded(), "must be loaded");
   if (!is_linked()) {
-    HandleMark hm(THREAD);
     instanceKlassHandle this_k(THREAD, this);
     link_class_impl(this_k, true, CHECK);
   }
@@ -512,7 +511,6 @@
 bool InstanceKlass::link_class_or_fail(TRAPS) {
   assert(is_loaded(), "must be loaded");
   if (!is_linked()) {
-    HandleMark hm(THREAD);
     instanceKlassHandle this_k(THREAD, this);
     link_class_impl(this_k, false, CHECK_false);
   }
@@ -565,7 +563,6 @@
   Array<Klass*>* interfaces = this_k->local_interfaces();
   int num_interfaces = interfaces->length();
   for (int index = 0; index < num_interfaces; index++) {
-    HandleMark hm(THREAD);
     instanceKlassHandle ih(THREAD, interfaces->at(index));
     link_class_impl(ih, throw_verifyerror, CHECK_false);
   }
@@ -586,11 +583,13 @@
 
   // verification & rewriting
   {
-    oop init_lock = this_k->init_lock();
-    ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
+    HandleMark hm(THREAD);
+    Handle init_lock(THREAD, this_k->init_lock());
+    ObjectLocker ol(init_lock, THREAD, init_lock() != NULL);
     // rewritten will have been set if loader constraint error found
     // on an earlier link attempt
     // don't verify or rewrite if already rewritten
+    //
 
     if (!this_k->is_linked()) {
       if (!this_k->is_rewritten()) {
@@ -700,6 +699,8 @@
 }
 
 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
+  HandleMark hm(THREAD);
+
   // Make sure klass is linked (verified) before initialization
   // A class could already be verified, since it has been reflected upon.
   this_k->link_class(CHECK);
@@ -711,8 +712,8 @@
   // refer to the JVM book page 47 for description of steps
   // Step 1
   {
-    oop init_lock = this_k->init_lock();
-    ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
+    Handle init_lock(THREAD, this_k->init_lock());
+    ObjectLocker ol(init_lock, THREAD, init_lock() != NULL);
 
     Thread *self = THREAD; // it's passed the current thread
 
@@ -853,14 +854,14 @@
 }
 
 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_k, ClassState state, TRAPS) {
-  oop init_lock = this_k->init_lock();
-  if (init_lock != NULL) {
+  Handle init_lock(THREAD, this_k->init_lock());
+  if (init_lock() != NULL) {
     ObjectLocker ol(init_lock, THREAD);
     this_k->set_init_state(state);
     this_k->fence_and_clear_init_lock();
     ol.notify_all(CHECK);
   } else {
-    assert(init_lock != NULL, "The initialization state should never be set twice");
+    assert(init_lock() != NULL, "The initialization state should never be set twice");
     this_k->set_init_state(state);
   }
 }
@@ -2300,7 +2301,8 @@
 void InstanceKlass::set_package(ClassLoaderData* loader_data, TRAPS) {
 
   // ensure java/ packages only loaded by boot or platform builtin loaders
-  check_prohibited_package(name(), loader_data->class_loader(), CHECK);
+  Handle class_loader(THREAD, loader_data->class_loader());
+  check_prohibited_package(name(), class_loader, CHECK);
 
   TempNewSymbol pkg_name = package_from_name(name(), CHECK);
 
@@ -2460,7 +2462,7 @@
                                              TRAPS) {
   ResourceMark rm(THREAD);
   if (!class_loader.is_null() &&
-      !SystemDictionary::is_platform_class_loader(class_loader) &&
+      !SystemDictionary::is_platform_class_loader(class_loader()) &&
       class_name != NULL &&
       strncmp(class_name->as_C_string(), JAVAPKG, JAVAPKG_LEN) == 0) {
     TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
@@ -3140,7 +3142,7 @@
         // source is unknown
       }
     } else {
-      Handle class_loader(loader_data->class_loader());
+      oop class_loader = loader_data->class_loader();
       log->print(" source: %s", class_loader->klass()->external_name());
     }
   } else {
--- a/hotspot/src/share/vm/oops/klass.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/oops/klass.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -519,7 +519,7 @@
   // Only recreate it if not present.  A previous attempt to restore may have
   // gotten an OOM later but keep the mirror if it was created.
   if (java_mirror() == NULL) {
-    Handle loader = loader_data->class_loader();
+    Handle loader(THREAD, loader_data->class_loader());
     ModuleEntry* module_entry = NULL;
     Klass* k = this;
     if (k->is_objArray_klass()) {
--- a/hotspot/src/share/vm/oops/oop.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/oops/oop.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -96,9 +96,10 @@
 
 intptr_t oopDesc::slow_identity_hash() {
   // slow case; we have to acquire the micro lock in order to locate the header
+  Thread* THREAD = Thread::current();
   ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
-  HandleMark hm;
-  Handle object(this);
+  HandleMark hm(THREAD);
+  Handle object(THREAD, this);
   return ObjectSynchronizer::identity_hash_value_for(object);
 }
 
--- a/hotspot/src/share/vm/opto/bytecodeInfo.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/opto/bytecodeInfo.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -496,6 +496,8 @@
       C->log()->inline_fail(inline_msg);
     }
   }
+  CompileTask::print_inlining_ul(callee_method, inline_level(),
+                                               caller_bci, inline_msg);
   if (C->print_inlining()) {
     C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
     if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
--- a/hotspot/src/share/vm/opto/library_call.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -387,8 +387,11 @@
   // Try to inline the intrinsic.
   if ((CheckIntrinsics ? callee->intrinsic_candidate() : true) &&
       kit.try_to_inline(_last_predicate)) {
+    const char *inline_msg = is_virtual() ? "(intrinsic, virtual)"
+                                          : "(intrinsic)";
+    CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg);
     if (C->print_intrinsics() || C->print_inlining()) {
-      C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
+      C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg);
     }
     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
     if (C->log()) {
@@ -404,22 +407,30 @@
   }
 
   // The intrinsic bailed out
-  if (C->print_intrinsics() || C->print_inlining()) {
-    if (jvms->has_method()) {
-      // Not a root compile.
-      const char* msg;
-      if (callee->intrinsic_candidate()) {
-        msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
-      } else {
-        msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated"
-                           : "failed to inline (intrinsic), method not annotated";
-      }
+  if (jvms->has_method()) {
+    // Not a root compile.
+    const char* msg;
+    if (callee->intrinsic_candidate()) {
+      msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
+    } else {
+      msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated"
+                         : "failed to inline (intrinsic), method not annotated";
+    }
+    CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
       C->print_inlining(callee, jvms->depth() - 1, bci, msg);
-    } else {
-      // Root compile
-      tty->print("Did not generate intrinsic %s%s at bci:%d in",
-               vmIntrinsics::name_at(intrinsic_id()),
-               (is_virtual() ? " (virtual)" : ""), bci);
+    }
+  } else {
+    // Root compile
+    ResourceMark rm;
+    stringStream msg_stream;
+    msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
+                     vmIntrinsics::name_at(intrinsic_id()),
+                     is_virtual() ? " (virtual)" : "", bci);
+    const char *msg = msg_stream.as_string();
+    log_debug(jit, inlining)("%s", msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
+      tty->print("%s", msg);
     }
   }
   C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
@@ -445,8 +456,11 @@
 
   Node* slow_ctl = kit.try_to_predicate(predicate);
   if (!kit.failing()) {
+    const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)"
+                                          : "(intrinsic, predicate)";
+    CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg);
     if (C->print_intrinsics() || C->print_inlining()) {
-      C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual, predicate)" : "(intrinsic, predicate)");
+      C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg);
     }
     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
     if (C->log()) {
@@ -459,16 +473,24 @@
   }
 
   // The intrinsic bailed out
-  if (C->print_intrinsics() || C->print_inlining()) {
-    if (jvms->has_method()) {
-      // Not a root compile.
-      const char* msg = "failed to generate predicate for intrinsic";
+  if (jvms->has_method()) {
+    // Not a root compile.
+    const char* msg = "failed to generate predicate for intrinsic";
+    CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
       C->print_inlining(kit.callee(), jvms->depth() - 1, bci, msg);
-    } else {
-      // Root compile
-      C->print_inlining_stream()->print("Did not generate predicate for intrinsic %s%s at bci:%d in",
-                                        vmIntrinsics::name_at(intrinsic_id()),
-                                        (is_virtual() ? " (virtual)" : ""), bci);
+    }
+  } else {
+    // Root compile
+    ResourceMark rm;
+    stringStream msg_stream;
+    msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
+                     vmIntrinsics::name_at(intrinsic_id()),
+                     is_virtual() ? " (virtual)" : "", bci);
+    const char *msg = msg_stream.as_string();
+    log_debug(jit, inlining)("%s", msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
+      C->print_inlining_stream()->print("%s", msg);
     }
   }
   C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
--- a/hotspot/src/share/vm/prims/jvm.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -549,9 +549,9 @@
     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
   }
 
-  Handle result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count,
-                                  start_index, frames_array_h, CHECK_NULL);
-  return JNIHandles::make_local(env, result());
+  oop result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count,
+                               start_index, frames_array_h, CHECK_NULL);
+  return JNIHandles::make_local(env, result);
 JVM_END
 
 
@@ -684,7 +684,7 @@
       // This can safepoint and redefine method, so need both new_obj and method
       // in a handle, for two different reasons.  new_obj can move, method can be
       // deleted if nothing is using it on the stack.
-      m->method_holder()->add_member_name(new_obj());
+      m->method_holder()->add_member_name(new_obj);
     }
   }
 
--- a/hotspot/src/share/vm/prims/jvmtiEnvBase.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/jvmtiEnvBase.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -598,7 +598,8 @@
 jclass
 JvmtiEnvBase::get_jni_class_non_null(Klass* k) {
   assert(k != NULL, "k != NULL");
-  return (jclass)jni_reference(k->java_mirror());
+  Thread *thread = Thread::current();
+  return (jclass)jni_reference(Handle(thread, k->java_mirror()));
 }
 
 //
@@ -693,7 +694,7 @@
     *monitor_ptr = NULL;
   } else {
     HandleMark hm;
-    Handle     hobj(obj);
+    Handle     hobj(Thread::current(), obj);
     *monitor_ptr = jni_reference(calling_thread, hobj);
   }
   return JVMTI_ERROR_NONE;
@@ -813,7 +814,7 @@
     if (err != JVMTI_ERROR_NONE) {
         return err;
     }
-    Handle hobj(obj);
+    Handle hobj(Thread::current(), obj);
     jmsdi->monitor = jni_reference(calling_thread, hobj);
     jmsdi->stack_depth = stack_depth;
     owned_monitors_list->append(jmsdi);
@@ -953,6 +954,7 @@
   HandleMark hm;
   Handle hobj;
 
+  Thread* current_thread = Thread::current();
   bool at_safepoint = SafepointSynchronize::is_at_safepoint();
 
   // Check arguments
@@ -961,7 +963,7 @@
     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
 
-    hobj = Handle(mirror);
+    hobj = Handle(current_thread, mirror);
   }
 
   JavaThread *owning_thread = NULL;
@@ -1027,7 +1029,7 @@
           return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
         }
         HandleMark hm;
-        Handle     th(owning_thread->threadObj());
+        Handle     th(current_thread, owning_thread->threadObj());
         ret.owner = (jthread)jni_reference(calling_thread, th);
       }
       // implied else: no owner
@@ -1110,7 +1112,7 @@
             deallocate((unsigned char*)ret.notify_waiters);
             return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
           }
-          Handle th(pending_thread->threadObj());
+          Handle th(current_thread, pending_thread->threadObj());
           ret.waiters[i] = (jthread)jni_reference(calling_thread, th);
         }
       }
@@ -1130,7 +1132,7 @@
             // If the thread was found on the ObjectWaiter list, then
             // it has not been notified. This thread can't change the
             // state of the monitor so it doesn't need to be suspended.
-            Handle th(wjava_thread->threadObj());
+            Handle th(current_thread, wjava_thread->threadObj());
             ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th);
             ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th);
           }
@@ -1362,7 +1364,7 @@
   // Check that the jobject class matches the return type signature.
   jobject jobj = value.l;
   if (tos == atos && jobj != NULL) { // NULL reference is allowed
-    Handle ob_h = Handle(current_thread, JNIHandles::resolve_external_guard(jobj));
+    Handle ob_h(current_thread, JNIHandles::resolve_external_guard(jobj));
     NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
     KlassHandle ob_kh = KlassHandle(current_thread, ob_h()->klass());
     NULL_CHECK(ob_kh, JVMTI_ERROR_INVALID_OBJECT);
@@ -1425,7 +1427,7 @@
       return JVMTI_ERROR_OPAQUE_FRAME;
     }
   }
-  Handle ret_ob_h = Handle();
+  Handle ret_ob_h;
   jvmtiError err = check_top_frame(current_thread, java_thread, value, tos, &ret_ob_h);
   if (err != JVMTI_ERROR_NONE) {
     return err;
@@ -1479,7 +1481,7 @@
         _error = err;
         return;
       }
-      Handle hobj(obj);
+      Handle hobj(Thread::current(), obj);
       jmsdi->monitor = _env->jni_reference(_calling_thread, hobj);
       // stack depth is unknown for this monitor.
       jmsdi->stack_depth = -1;
--- a/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -36,15 +36,16 @@
 private:
   Stack<jclass, mtInternal> _classStack;
   JvmtiEnv* _env;
+  Thread*   _cur_thread;
 
 public:
-  LoadedClassesClosure(JvmtiEnv* env) {
-    _env = env;
+  LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
+    assert(_cur_thread == Thread::current(), "must be current thread");
   }
 
   void do_klass(Klass* k) {
     // Collect all jclasses
-    _classStack.push((jclass) _env->jni_reference(k->java_mirror()));
+    _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
   }
 
   int extract(jclass* result_list) {
@@ -225,8 +226,9 @@
     if (that->available()) {
       oop class_loader = loader_data->class_loader();
       if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) {
+        Thread *thread = Thread::current();
         for (Klass* l = k; l != NULL; l = l->array_klass_or_null()) {
-          oop mirror = l->java_mirror();
+          Handle mirror(thread, l->java_mirror());
           that->set_element(that->get_index(), mirror);
           that->set_index(that->get_index() + 1);
         }
@@ -250,8 +252,9 @@
     JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
     assert(that != NULL, "no JvmtiGetLoadedClassesClosure");
     assert(that->available(), "no list");
+    Thread *thread = Thread::current();
     for (Klass* l = k; l != NULL; l = l->array_klass_or_null()) {
-      oop mirror = l->java_mirror();
+      Handle mirror(thread, l->java_mirror());
       that->set_element(that->get_index(), mirror);
       that->set_index(that->get_index() + 1);
     }
@@ -262,7 +265,7 @@
 jvmtiError
 JvmtiGetLoadedClasses::getLoadedClasses(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) {
 
-  LoadedClassesClosure closure(env);
+  LoadedClassesClosure closure(Thread::current(), env);
   {
     // To get a consistent list of classes we need MultiArray_lock to ensure
     // array classes aren't created.
--- a/hotspot/src/share/vm/prims/jvmtiImpl.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/jvmtiImpl.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -694,7 +694,7 @@
     JavaThread* cur_thread = JavaThread::current();
     HandleMark hm(cur_thread);
 
-    Handle obj = Handle(cur_thread, JNIHandles::resolve_external_guard(jobj));
+    Handle obj(cur_thread, JNIHandles::resolve_external_guard(jobj));
     NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
     KlassHandle ob_kh = KlassHandle(cur_thread, obj->klass());
     NULL_CHECK(ob_kh, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
@@ -777,7 +777,7 @@
       case T_FLOAT:  locals->set_float_at (_index, _value.f); break;
       case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
       case T_OBJECT: {
-        Handle ob_h(JNIHandles::resolve_external_guard(_value.l));
+        Handle ob_h(Thread::current(), JNIHandles::resolve_external_guard(_value.l));
         locals->set_obj_at (_index, ob_h);
         break;
       }
--- a/hotspot/src/share/vm/prims/jvmtiThreadState.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/jvmtiThreadState.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -418,7 +418,7 @@
                      JvmtiThreadState *state) : _state(state), _scratch_class(*scratch_class)
   {
     _state->set_class_versions_map(the_class, scratch_class);
-    _scratch_mirror = Handle(_scratch_class->java_mirror());
+    _scratch_mirror = Handle(Thread::current(), _scratch_class->java_mirror());
     (*scratch_class)->set_java_mirror((*the_class)->java_mirror());
   }
 
--- a/hotspot/src/share/vm/prims/methodHandles.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -833,8 +833,8 @@
       }
       if (!have_name) {
         //not java_lang_String::create_from_symbol; let's intern member names
-        Handle name = StringTable::intern(m->name(), CHECK);
-        java_lang_invoke_MemberName::set_name(mname(), name());
+        oop name = StringTable::intern(m->name(), CHECK);
+        java_lang_invoke_MemberName::set_name(mname(), name);
       }
       if (!have_type) {
         Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK);
@@ -857,14 +857,14 @@
       }
       if (!have_name) {
         //not java_lang_String::create_from_symbol; let's intern member names
-        Handle name = StringTable::intern(fd.name(), CHECK);
-        java_lang_invoke_MemberName::set_name(mname(), name());
+        oop name = StringTable::intern(fd.name(), CHECK);
+        java_lang_invoke_MemberName::set_name(mname(), name);
       }
       if (!have_type) {
         // If it is a primitive field type, don't mess with short strings like "I".
-        Handle type = field_signature_type_or_null(fd.signature());
+        Handle type (THREAD, field_signature_type_or_null(fd.signature()));
         if (type.is_null()) {
-          java_lang_String::create_from_symbol(fd.signature(), CHECK);
+          type = java_lang_String::create_from_symbol(fd.signature(), CHECK);
         }
         java_lang_invoke_MemberName::set_type(mname(), type());
       }
@@ -1019,7 +1019,7 @@
   assert_lock_strong(Compile_lock);
 
   int marked = 0;
-  CallSiteDepChange changes(call_site(), target());
+  CallSiteDepChange changes(call_site, target);
   {
     NoSafepointVerifier nsv;
     MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
@@ -1283,7 +1283,7 @@
   Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
   intptr_t vmindex  = java_lang_invoke_MemberName::vmindex(mname());
   Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
-  objArrayHandle result = oopFactory::new_objArray(SystemDictionary::Object_klass(), 2, CHECK_NULL);
+  objArrayHandle result = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 2, CHECK_NULL);
   jvalue vmindex_value; vmindex_value.j = (long)vmindex;
   oop x = java_lang_boxing_object::create(T_LONG, &vmindex_value, CHECK_NULL);
   result->obj_at_put(0, x);
--- a/hotspot/src/share/vm/prims/stackwalk.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/stackwalk.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -274,7 +274,7 @@
 // Fill StackFrameInfo with declaringClass and bci and initialize memberName
 void BaseFrameStream::fill_stackframe(Handle stackFrame, const methodHandle& method) {
   java_lang_StackFrameInfo::set_declaringClass(stackFrame(), method->method_holder()->java_mirror());
-  java_lang_StackFrameInfo::set_method_and_bci(stackFrame(), method, bci());
+  java_lang_StackFrameInfo::set_method_and_bci(stackFrame, method, bci());
 }
 
 // Fill LiveStackFrameInfo with locals, monitors, and expressions
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -124,8 +124,8 @@
 };
 
 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name))
-  Handle h_name = JNIHandles::resolve(name);
-  if (h_name.is_null()) return false;
+  oop h_name = JNIHandles::resolve(name);
+  if (h_name == NULL) return false;
   Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false);
   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 
@@ -1914,7 +1914,7 @@
     if (WhiteBoxAPI) {
       // Make sure that wbclass is loaded by the null classloader
       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
-      Handle loader(ikh->class_loader());
+      Handle loader(THREAD, ikh->class_loader());
       if (loader.is_null()) {
         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
         WhiteBox::register_extended(env, wbclass, thread);
--- a/hotspot/src/share/vm/runtime/deoptimization.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/deoptimization.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -451,7 +451,6 @@
   // Compute whether the root vframe returns a float or double value.
   BasicType return_type;
   {
-    HandleMark hm;
     methodHandle method(thread, array->element(0)->method());
     Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci());
     return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL;
@@ -799,7 +798,7 @@
 
 #if defined(COMPILER2) || INCLUDE_JVMCI
 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
-  Handle pending_exception(thread->pending_exception());
+  Handle pending_exception(THREAD, thread->pending_exception());
   const char* exception_file = thread->exception_file();
   int exception_line = thread->exception_line();
   thread->clear_pending_exception();
@@ -1109,7 +1108,7 @@
     if (mon_info->eliminated()) {
       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
       if (!mon_info->owner_is_scalar_replaced()) {
-        Handle obj = Handle(mon_info->owner());
+        Handle obj(thread, mon_info->owner());
         markOop mark = obj->mark();
         if (UseBiasedLocking && mark->has_bias_pattern()) {
           // New allocated objects may have the mark set to anonymously biased.
@@ -1246,10 +1245,11 @@
 
 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
+  Thread* thread = Thread::current();
   for (int i = 0; i < monitors->length(); i++) {
     MonitorInfo* mon_info = monitors->at(i);
     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
-      objects_to_revoke->append(Handle(mon_info->owner()));
+      objects_to_revoke->append(Handle(thread, mon_info->owner()));
     }
   }
 }
--- a/hotspot/src/share/vm/runtime/handles.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/handles.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -37,15 +37,6 @@
   assert(obj->is_oop(), "not an oop: " INTPTR_FORMAT, p2i(obj));
   return real_allocate_handle(obj);
 }
-
-Handle::Handle(Thread* thread, oop obj) {
-  assert(thread == Thread::current(), "sanity check");
-  if (obj == NULL) {
-    _handle = NULL;
-  } else {
-    _handle = thread->handle_area()->allocate_handle(obj);
-  }
-}
 #endif
 
 // Copy constructors and destructors for metadata handles
--- a/hotspot/src/share/vm/runtime/handles.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/handles.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -45,8 +45,7 @@
 // Handles are declared in a straight-forward manner, e.g.
 //
 //   oop obj = ...;
-//   Handle h1(obj);              // allocate new handle
-//   Handle h2(thread, obj);      // faster allocation when current thread is known
+//   Handle h2(thread, obj);      // allocate a new handle in thread
 //   Handle h3;                   // declare handle only, no allocation occurs
 //   ...
 //   h3 = h1;                     // make h3 refer to same indirection as h1
@@ -55,11 +54,7 @@
 //
 // Handles are specialized for different oop types to provide extra type
 // information and avoid unnecessary casting. For each oop type xxxOop
-// there is a corresponding handle called xxxHandle, e.g.
-//
-//   oop           Handle
-//   Method*       methodHandle
-//   instanceOop   instanceHandle
+// there is a corresponding handle called xxxHandle.
 
 //------------------------------------------------------------------------------------------------------------------------
 // Base class for all handles. Provides overloading of frequently
@@ -76,7 +71,6 @@
  public:
   // Constructors
   Handle()                                       { _handle = NULL; }
-  Handle(oop obj);
   Handle(Thread* thread, oop obj);
 
   // General access
@@ -113,10 +107,6 @@
    public:                                       \
     /* Constructors */                           \
     type##Handle ()                              : Handle()                 {} \
-    type##Handle (type##Oop obj) : Handle((oop)obj) {                         \
-      assert(is_null() || ((oop)obj)->is_a(),                                 \
-             "illegal type");                                                 \
-    }                                                                         \
     type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \
       assert(is_null() || ((oop)obj)->is_a(), "illegal type");                \
     }                                                                         \
@@ -277,7 +267,7 @@
 //   Handle h;
 //   {
 //     HandleMark hm;
-//     h = Handle(obj);
+//     h = Handle(THREAD, obj);
 //   }
 //   h()->print();       // WRONG, h destroyed by HandleMark destructor.
 //
--- a/hotspot/src/share/vm/runtime/handles.inline.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/handles.inline.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -31,16 +31,6 @@
 // these inline functions are in a separate file to break an include cycle
 // between Thread and Handle
 
-inline Handle::Handle(oop obj) {
-  if (obj == NULL) {
-    _handle = NULL;
-  } else {
-    _handle = Thread::current()->handle_area()->allocate_handle(obj);
-  }
-}
-
-
-#ifndef ASSERT
 inline Handle::Handle(Thread* thread, oop obj) {
   assert(thread == Thread::current(), "sanity check");
   if (obj == NULL) {
@@ -49,7 +39,6 @@
     _handle = thread->handle_area()->allocate_handle(obj);
   }
 }
-#endif // ASSERT
 
 // Constructors for metadata handles
 #define DEF_METADATA_HANDLE_FN(name, type) \
--- a/hotspot/src/share/vm/runtime/java.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/java.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -99,9 +99,6 @@
 
 void collect_profiled_methods(Method* m) {
   Thread* thread = Thread::current();
-  // This HandleMark prevents a huge amount of handles from being added
-  // to the metadata_handles() array on the thread.
-  HandleMark hm(thread);
   methodHandle mh(thread, m);
   if ((m->method_data() != NULL) &&
       (PrintMethodData || CompilerOracle::should_print(mh))) {
--- a/hotspot/src/share/vm/runtime/os.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/os.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -347,10 +347,9 @@
   VM_Version::init_before_ergo();
 }
 
-void os::signal_init() {
+void os::signal_init(TRAPS) {
   if (!ReduceSignalUsage) {
     // Setup JavaThread for processing signals
-    EXCEPTION_MARK;
     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK);
     instanceKlassHandle klass (THREAD, k);
     instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
--- a/hotspot/src/share/vm/runtime/os.hpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/os.hpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -731,7 +731,7 @@
   static struct hostent* get_host_by_name(char* name);
 
   // Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
-  static void  signal_init();
+  static void  signal_init(TRAPS);
   static void  signal_init_pd();
   static void  signal_notify(int signal_number);
   static void* signal(int signal_number, void* handler);
--- a/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -2891,9 +2891,11 @@
 
   // Install the generated code.
   if (nm != NULL) {
+    const char *msg = method->is_static() ? "(static)" : "";
+    CompileTask::print_ul(nm, msg);
     if (PrintCompilation) {
       ttyLocker ttyl;
-      CompileTask::print(tty, nm, method->is_static() ? "(static)" : "");
+      CompileTask::print(tty, nm, msg);
     }
     nm->post_compiled_method_load_event();
   }
--- a/hotspot/src/share/vm/runtime/stackValue.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/stackValue.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -103,7 +103,7 @@
         value.noop = *(narrowOop*) value_addr;
       }
       // Decode narrowoop and wrap a handle around the oop
-      Handle h(oopDesc::decode_heap_oop(value.noop));
+      Handle h(Thread::current(), oopDesc::decode_heap_oop(value.noop));
       return new StackValue(h);
     }
 #endif
@@ -118,7 +118,7 @@
          val = (oop)NULL;
       }
 #endif
-      Handle h(val); // Wrap a handle around the oop
+      Handle h(Thread::current(), val); // Wrap a handle around the oop
       return new StackValue(h);
     }
     case Location::addr: {
--- a/hotspot/src/share/vm/runtime/sweeper.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/sweeper.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -403,6 +403,8 @@
   ResourceMark rm;
   Ticks sweep_start_counter = Ticks::now();
 
+  log_debug(codecache, sweep, start)("CodeCache flushing");
+
   int flushed_count                = 0;
   int zombified_count              = 0;
   int flushed_c2_count     = 0;
@@ -500,6 +502,10 @@
   }
 #endif
 
+  Log(codecache, sweep) log;
+  if (log.is_debug()) {
+    CodeCache::print_summary(log.debug_stream(), false);
+  }
   log_sweep("finished");
 
   // Sweeper is the only case where memory is released, check here if it
@@ -513,6 +519,7 @@
   // cache. As a result, 'freed_memory' > 0 to restart the compiler.
   if (!CompileBroker::should_compile_new_jobs() && (freed_memory > 0)) {
     CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
+    log.debug("restart compiler");
     log_sweep("restart_compiler");
   }
 }
--- a/hotspot/src/share/vm/runtime/synchronizer.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/synchronizer.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -1762,7 +1762,7 @@
     if (mid->owner() == THREAD) {
       if (ObjectMonitor::Knob_VerifyMatch != 0) {
         ResourceMark rm;
-        Handle obj((oop) mid->object());
+        Handle obj(THREAD, (oop) mid->object());
         tty->print("INFO: unexpected locked object:");
         javaVFrame::print_locked_object_class_name(tty, obj, "locked");
         fatal("exiting JavaThread=" INTPTR_FORMAT
--- a/hotspot/src/share/vm/runtime/thread.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -3717,7 +3717,7 @@
 #endif // INCLUDE_MANAGEMENT
 
   // Signal Dispatcher needs to be started before VMInit event is posted
-  os::signal_init();
+  os::signal_init(CHECK_JNI_ERR);
 
   // Start Attach Listener if +StartAttachListener or it can't be started lazily
   if (!DisableAttachMechanism) {
--- a/hotspot/src/share/vm/runtime/vframe.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/vframe.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -155,7 +155,8 @@
 }
 
 void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) {
-  ResourceMark rm;
+  Thread* THREAD = Thread::current();
+  ResourceMark rm(THREAD);
 
   // If this is the first frame and it is java.lang.Object.wait(...)
   // then print out the receiver. Locals are not always available,
@@ -201,8 +202,8 @@
           // format below for lockbits matches this one.
           st->print("\t- eliminated <owner is scalar replaced> (a %s)", k->external_name());
         } else {
-          oop obj = monitor->owner();
-          if (obj != NULL) {
+          Handle obj(THREAD, monitor->owner());
+          if (obj() != NULL) {
             print_locked_object_class_name(st, obj, "eliminated");
           }
         }
@@ -252,7 +253,7 @@
             mark = NULL;
           }
         }
-        print_locked_object_class_name(st, monitor->owner(), lock_state);
+        print_locked_object_class_name(st, Handle(THREAD, monitor->owner()), lock_state);
         if (ObjectMonitor::Knob_Verbose && mark != NULL) {
           st->print("\t- lockbits=");
           mark->print_on(st);
@@ -309,7 +310,7 @@
   // categorize using oop_mask
   if (oop_mask.is_oop(index)) {
     // reference (oop) "r"
-    Handle h(addr != NULL ? (*(oop*)addr) : (oop)NULL);
+    Handle h(Thread::current(), addr != NULL ? (*(oop*)addr) : (oop)NULL);
     return new StackValue(h);
   }
   // value (integer) "v"
--- a/hotspot/src/share/vm/runtime/vframe_hp.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/runtime/vframe_hp.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -106,7 +106,7 @@
         break;
       case T_OBJECT:
         {
-          Handle obj((oop)val->value().l);
+          Handle obj(Thread::current(), (oop)val->value().l);
           result->set_obj_at(val->index(), obj);
         }
         break;
@@ -227,7 +227,7 @@
       // Put klass for scalar replaced object.
       ScopeValue* kv = ((ObjectValue *)ov)->klass();
       assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object");
-      Handle k(((ConstantOopReadValue*)kv)->value()());
+      Handle k(Thread::current(), ((ConstantOopReadValue*)kv)->value()());
       assert(java_lang_Class::is_instance(k()), "must be");
       result->push(new MonitorInfo(k(), resolve_monitor_lock(mv->basic_lock()),
                                    mv->eliminated(), true));
--- a/hotspot/src/share/vm/services/gcNotifier.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/services/gcNotifier.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -178,7 +178,7 @@
                           &constructor_args,
                           CHECK_NH);
 
-  return Handle(gcInfo_instance());
+  return Handle(THREAD, gcInfo_instance());
 }
 
 void GCNotifier::sendNotification(TRAPS) {
--- a/hotspot/src/share/vm/services/management.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/services/management.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -1953,7 +1953,8 @@
     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
                "Output file name cannot be null.", -1);
   }
-  char* name = java_lang_String::as_platform_dependent_str(on, CHECK_(-1));
+  Handle onhandle(THREAD, on);
+  char* name = java_lang_String::as_platform_dependent_str(onhandle, CHECK_(-1));
   if (name == NULL) {
     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
                "Output file name cannot be null.", -1);
--- a/hotspot/src/share/vm/services/threadService.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/services/threadService.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -166,7 +166,7 @@
     // If obj == NULL, then ObjectMonitor is raw which doesn't count.
   }
 
-  Handle h(obj);
+  Handle h(Thread::current(), obj);
   return h;
 }
 
--- a/hotspot/src/share/vm/utilities/exceptions.cpp	Wed Feb 22 12:33:36 2017 -0500
+++ b/hotspot/src/share/vm/utilities/exceptions.cpp	Wed Feb 22 12:34:32 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -129,7 +129,7 @@
 // therefore the exception oop should be in the oopmap.
 void Exceptions::_throw_oop(Thread* thread, const char* file, int line, oop exception) {
   assert(exception != NULL, "exception should not be NULL");
-  Handle h_exception = Handle(thread, exception);
+  Handle h_exception(thread, exception);
   _throw(thread, file, line, h_exception);
 }
 
@@ -496,7 +496,7 @@
 void Exceptions::debug_check_abort_helper(Handle exception, const char* message) {
   ResourceMark rm;
   if (message == NULL && exception->is_a(SystemDictionary::Throwable_klass())) {
-    oop msg = java_lang_Throwable::message(exception);
+    oop msg = java_lang_Throwable::message(exception());
     if (msg != NULL) {
       message = java_lang_String::as_utf8_string(msg);
     }