changeset 6980:e26ce0e8b666

Merge
author zgu
date Fri, 09 Nov 2012 16:45:20 -0800
parents fb3190e77d3c (current diff) 8aaef2cee3b2 (diff)
children 8c413497f434
files
diffstat 45 files changed, 339 insertions(+), 272 deletions(-) [+]
line wrap: on
line diff
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java	Fri Nov 09 19:24:31 2012 -0500
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java	Fri Nov 09 16:45:20 2012 -0800
@@ -121,7 +121,7 @@
     Address addr = cache.getValue(getAddress());
     return (ConstantPoolCache) VMObjectFactory.newObject(ConstantPoolCache.class, addr);
   }
-  public Klass             getPoolHolder() { return (Klass)             poolHolder.getValue(this); }
+  public InstanceKlass     getPoolHolder() { return (InstanceKlass)poolHolder.getValue(this); }
   public int               getLength()     { return (int)length.getValue(getAddress()); }
   public Oop               getResolvedReferences() {
     Address handle = resolvedReferences.getValue(getAddress());
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/Method.java	Fri Nov 09 19:24:31 2012 -0500
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Method.java	Fri Nov 09 16:45:20 2012 -0800
@@ -177,7 +177,7 @@
       bci. It is required that there is currently a bytecode at this
       bci. */
   public int getOrigBytecodeAt(int bci) {
-    BreakpointInfo bp = ((InstanceKlass) getMethodHolder()).getBreakpoints();
+    BreakpointInfo bp = getMethodHolder().getBreakpoints();
     for (; bp != null; bp = bp.getNext()) {
       if (bp.match(this, bci)) {
         return bp.getOrigBytecode();
@@ -238,7 +238,7 @@
   }
 
   // Method holder (the Klass holding this method)
-  public Klass   getMethodHolder()  { return getConstants().getPoolHolder();                           }
+  public InstanceKlass   getMethodHolder()  { return getConstants().getPoolHolder();                   }
 
   // Access flags
   public boolean isPublic()         { return getAccessFlagsObj().isPublic();                           }
--- a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -2322,7 +2322,7 @@
   // Pre-load a static method's oop into O1.  Used both by locking code and
   // the normal JNI call code.
   if (method->is_static() && !is_critical_native) {
-    __ set_oop_constant(JNIHandles::make_local(Klass::cast(method->method_holder())->java_mirror()), O1);
+    __ set_oop_constant(JNIHandles::make_local(method->method_holder()->java_mirror()), O1);
 
     // Now handlize the static class mirror in O1.  It's known not-null.
     __ st_ptr(O1, SP, klass_offset + STACK_BIAS);
--- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1936,7 +1936,7 @@
   if (method->is_static() && !is_critical_native) {
 
     //  load opp into a register
-    __ movoop(oop_handle_reg, JNIHandles::make_local(Klass::cast(method->method_holder())->java_mirror()));
+    __ movoop(oop_handle_reg, JNIHandles::make_local(method->method_holder()->java_mirror()));
 
     // Now handlize the static class mirror it's known not-null.
     __ movptr(Address(rsp, klass_offset), oop_handle_reg);
--- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -2179,7 +2179,7 @@
   if (method->is_static() && !is_critical_native) {
 
     //  load oop into a register
-    __ movoop(oop_handle_reg, JNIHandles::make_local(Klass::cast(method->method_holder())->java_mirror()));
+    __ movoop(oop_handle_reg, JNIHandles::make_local(method->method_holder()->java_mirror()));
 
     // Now handlize the static class mirror it's known not-null.
     __ movptr(Address(rsp, klass_offset), oop_handle_reg);
--- a/src/share/vm/ci/ciEnv.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/ci/ciEnv.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -768,8 +768,8 @@
       Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
       if (m != NULL &&
           (bc == Bytecodes::_invokestatic
-           ?  InstanceKlass::cast(m->method_holder())->is_not_initialized()
-           : !InstanceKlass::cast(m->method_holder())->is_loaded())) {
+           ?  m->method_holder()->is_not_initialized()
+           : !m->method_holder()->is_loaded())) {
         m = NULL;
       }
       if (m != NULL) {
@@ -1056,7 +1056,7 @@
                         method_name,
                         entry_bci);
         }
-        InstanceKlass::cast(method->method_holder())->add_osr_nmethod(nm);
+        method->method_holder()->add_osr_nmethod(nm);
 
       }
     }
--- a/src/share/vm/ci/ciMethod.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/ci/ciMethod.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -105,7 +105,7 @@
     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
   }
 
-  if (InstanceKlass::cast(h_m()->method_holder())->is_linked()) {
+  if (h_m()->method_holder()->is_linked()) {
     _can_be_statically_bound = h_m()->can_be_statically_bound();
   } else {
     // Have to use a conservative value in this case.
@@ -188,7 +188,7 @@
 
   // Revert any breakpoint bytecodes in ci's copy
   if (me->number_of_breakpoints() > 0) {
-    BreakpointInfo* bp = InstanceKlass::cast(me->method_holder())->breakpoints();
+    BreakpointInfo* bp = me->method_holder()->breakpoints();
     for (; bp != NULL; bp = bp->next()) {
       if (bp->match(me)) {
         code_at_put(bp->bci(), bp->orig_bytecode());
--- a/src/share/vm/classfile/classFileParser.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/classfile/classFileParser.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -4193,7 +4193,7 @@
           }
 
           // continue to look from super_m's holder's super.
-          k = InstanceKlass::cast(super_m->method_holder())->super();
+          k = super_m->method_holder()->super();
           continue;
         }
 
--- a/src/share/vm/classfile/javaClasses.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/classfile/javaClasses.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1156,7 +1156,7 @@
 // Print stack trace element to resource allocated buffer
 char* java_lang_Throwable::print_stack_element_to_buffer(Method* method, int bci) {
   // Get strings and string lengths
-  InstanceKlass* klass = InstanceKlass::cast(method->method_holder());
+  InstanceKlass* klass = method->method_holder();
   const char* klass_name  = klass->external_name();
   int buf_len = (int)strlen(klass_name);
   char* source_file_name;
@@ -1747,14 +1747,14 @@
   Handle element = ik->allocate_instance_handle(CHECK_0);
   // Fill in class name
   ResourceMark rm(THREAD);
-  const char* str = InstanceKlass::cast(method->method_holder())->external_name();
+  const char* str = method->method_holder()->external_name();
   oop classname = StringTable::intern((char*) str, CHECK_0);
   java_lang_StackTraceElement::set_declaringClass(element(), classname);
   // Fill in method name
   oop methodname = StringTable::intern(method->name(), CHECK_0);
   java_lang_StackTraceElement::set_methodName(element(), methodname);
   // Fill in source file name
-  Symbol* source = InstanceKlass::cast(method->method_holder())->source_file_name();
+  Symbol* source = method->method_holder()->source_file_name();
   if (ShowHiddenFrames && source == NULL)
     source = vmSymbols::unknown_class_name();
   oop filename = StringTable::intern(source, CHECK_0);
--- a/src/share/vm/classfile/verifier.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/classfile/verifier.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -446,7 +446,7 @@
           bytecode_name = "<illegal>";
       }
     }
-    InstanceKlass* ik = InstanceKlass::cast(method->method_holder());
+    InstanceKlass* ik = method->method_holder();
     ss->indent().print_cr("Location:");
     streamIndentor si2(ss);
     ss->indent().print_cr("%s.%s%s @%d: %s",
@@ -1850,7 +1850,7 @@
   if ((index <= 0) || (index >= nconstants)) {
     verify_error(ErrorContext::bad_cp_index(bci, index),
         "Illegal constant pool index %d in class %s",
-        index, InstanceKlass::cast(cp->pool_holder())->external_name());
+        index, cp->pool_holder()->external_name());
     return;
   }
 }
@@ -1869,7 +1869,7 @@
   if ((types & (1 << tag)) == 0) {
     verify_error(ErrorContext::bad_cp_index(bci, index),
       "Illegal type at constant pool entry %d in class %s",
-      index, InstanceKlass::cast(cp->pool_holder())->external_name());
+      index, cp->pool_holder()->external_name());
     return;
   }
 }
@@ -1881,7 +1881,7 @@
   if (!tag.is_klass() && !tag.is_unresolved_klass()) {
     verify_error(ErrorContext::bad_cp_index(bci, index),
         "Illegal type at constant pool entry %d in class %s",
-        index, InstanceKlass::cast(cp->pool_holder())->external_name());
+        index, cp->pool_holder()->external_name());
     return;
   }
 }
--- a/src/share/vm/classfile/vmSymbols.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/classfile/vmSymbols.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -507,7 +507,7 @@
 }
 
 void vmIntrinsics::verify_method(ID actual_id, Method* m) {
-  Symbol* mk = Klass::cast(m->method_holder())->name();
+  Symbol* mk = m->method_holder()->name();
   ID declared_id = match_method_with_klass(m, mk);
 
   if (declared_id == actual_id)  return; // success
--- a/src/share/vm/code/compiledIC.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/code/compiledIC.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -191,8 +191,8 @@
     int index = klassItable::compute_itable_index(call_info->resolved_method()());
     entry = VtableStubs::create_stub(false, index, method());
     assert(entry != NULL, "entry not computed");
-    Klass* k = call_info->resolved_method()->method_holder();
-    assert(Klass::cast(k)->is_interface(), "sanity check");
+    InstanceKlass* k = call_info->resolved_method()->method_holder();
+    assert(k->is_interface(), "sanity check");
     InlineCacheBuffer::create_transition_stub(this, k, entry);
   } else {
     // Can be different than method->vtable_index(), due to package-private etc.
--- a/src/share/vm/code/dependencies.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/code/dependencies.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -829,7 +829,7 @@
       }
       if (   !Dependencies::is_concrete_method(lm)
           && !Dependencies::is_concrete_method(m)
-          && Klass::cast(lm->method_holder())->is_subtype_of(m->method_holder()))
+          && lm->method_holder()->is_subtype_of(m->method_holder()))
         // Method m is overridden by lm, but both are non-concrete.
         return true;
     }
--- a/src/share/vm/code/nmethod.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/code/nmethod.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1263,7 +1263,7 @@
   assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod");
   // Remove from list of active nmethods
   if (method() != NULL)
-    InstanceKlass::cast(method()->method_holder())->remove_osr_nmethod(this);
+    method()->method_holder()->remove_osr_nmethod(this);
   // Set entry as invalid
   _entry_bci = InvalidOSREntryBci;
 }
--- a/src/share/vm/compiler/compileBroker.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/compiler/compileBroker.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1051,7 +1051,7 @@
   guarantee(!method->is_abstract(), "cannot compile abstract methods");
   assert(method->method_holder()->oop_is_instance(),
          "sanity check");
-  assert(!InstanceKlass::cast(method->method_holder())->is_not_initialized(),
+  assert(!method->method_holder()->is_not_initialized(),
          "method holder must be initialized");
   assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys");
 
@@ -1206,7 +1206,7 @@
   assert(method->method_holder()->oop_is_instance(), "not an instance method");
   assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
   assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
-  assert(!InstanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized");
+  assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized");
 
   if (!TieredCompilation) {
     comp_level = CompLevel_highest_tier;
--- a/src/share/vm/compiler/compilerOracle.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/compiler/compilerOracle.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -67,7 +67,7 @@
 
   // utility method
   MethodMatcher* find(methodHandle method) {
-    Symbol* class_name  = Klass::cast(method->method_holder())->name();
+    Symbol* class_name  = method->method_holder()->name();
     Symbol* method_name = method->name();
     for (MethodMatcher* current = this; current != NULL; current = current->_next) {
       if (match(class_name, current->class_name(), current->_class_mode) &&
@@ -624,7 +624,7 @@
   assert(has_command_file(), "command file must be specified");
   fileStream stream(fopen(cc_file(), "at"));
   stream.print("exclude ");
-  Klass::cast(method->method_holder())->name()->print_symbol_on(&stream);
+  method->method_holder()->name()->print_symbol_on(&stream);
   stream.print(".");
   method->name()->print_symbol_on(&stream);
   method->signature()->print_symbol_on(&stream);
--- a/src/share/vm/interpreter/linkResolver.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/interpreter/linkResolver.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -133,7 +133,7 @@
       // don't force compilation, resolve was on behalf of compiler
       return;
     }
-    if (InstanceKlass::cast(selected_method->method_holder())->is_not_initialized()) {
+    if (selected_method->method_holder()->is_not_initialized()) {
       // 'is_not_initialized' means not only '!is_initialized', but also that
       // initialization has not been started yet ('!being_initialized')
       // Do not force compilation of methods in uninitialized classes.
@@ -466,7 +466,7 @@
 
     // check loader constraints
     Handle loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());
-    Handle class_loader (THREAD, InstanceKlass::cast(resolved_method->method_holder())->class_loader());
+    Handle class_loader (THREAD, resolved_method->method_holder()->class_loader());
     {
       ResourceMark rm(THREAD);
       char* failed_type_name =
@@ -528,7 +528,7 @@
   if (check_access) {
     HandleMark hm(THREAD);
     Handle loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());
-    Handle class_loader (THREAD, InstanceKlass::cast(resolved_method->method_holder())->class_loader());
+    Handle class_loader (THREAD, resolved_method->method_holder()->class_loader());
     {
       ResourceMark rm(THREAD);
       char* failed_type_name =
@@ -910,12 +910,12 @@
 
   // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
   // has not been rewritten, and the vtable initialized.
-  assert(InstanceKlass::cast(resolved_method->method_holder())->is_linked(), "must be linked");
+  assert(resolved_method->method_holder()->is_linked(), "must be linked");
 
   // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
   // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
   // a missing receiver might result in a bogus lookup.
-  assert(InstanceKlass::cast(resolved_method->method_holder())->is_linked(), "must be linked");
+  assert(resolved_method->method_holder()->is_linked(), "must be linked");
 
   // do lookup based on receiver klass using the vtable index
   if (resolved_method->method_holder()->is_interface()) { // miranda method
--- a/src/share/vm/oops/constMethod.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/constMethod.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -113,8 +113,7 @@
 }
 
 Method* ConstMethod::method() const {
-    return InstanceKlass::cast(_constants->pool_holder())->method_with_idnum(
-                               _method_idnum);
+    return _constants->pool_holder()->method_with_idnum(_method_idnum);
   }
 
 // linenumber table - note that length is unknown until decompression,
--- a/src/share/vm/oops/constantPool.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/constantPool.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -228,7 +228,7 @@
       } else {
         do_resolve = true;
         name   = this_oop->unresolved_klass_at(which);
-        loader = Handle(THREAD, InstanceKlass::cast(this_oop->pool_holder())->class_loader());
+        loader = Handle(THREAD, this_oop->pool_holder()->class_loader());
       }
     }
   } // unlocking constantPool
@@ -247,7 +247,7 @@
 
   if (do_resolve) {
     // this_oop must be unlocked during resolve_or_fail
-    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
+    oop protection_domain = this_oop->pool_holder()->protection_domain();
     Handle h_prot (THREAD, protection_domain);
     Klass* k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
     KlassHandle k;
@@ -315,7 +315,7 @@
         vframeStream vfst(JavaThread::current());
         if (!vfst.at_end()) {
           line_number = vfst.method()->line_number_from_bci(vfst.bci());
-          Symbol* s = InstanceKlass::cast(vfst.method()->method_holder())->source_file_name();
+          Symbol* s = vfst.method()->method_holder()->source_file_name();
           if (s != NULL) {
             source_file = s->as_C_string();
           }
@@ -325,11 +325,11 @@
         // only print something if the classes are different
         if (source_file != NULL) {
           tty->print("RESOLVE %s %s %s:%d\n",
-                     InstanceKlass::cast(this_oop->pool_holder())->external_name(),
+                     this_oop->pool_holder()->external_name(),
                      InstanceKlass::cast(k())->external_name(), source_file, line_number);
         } else {
           tty->print("RESOLVE %s %s\n",
-                     InstanceKlass::cast(this_oop->pool_holder())->external_name(),
+                     this_oop->pool_holder()->external_name(),
                      InstanceKlass::cast(k())->external_name());
         }
       }
@@ -339,7 +339,7 @@
       // Only updated constant pool - if it is resolved.
       do_resolve = this_oop->tag_at(which).is_unresolved_klass();
       if (do_resolve) {
-        ClassLoaderData* this_key = InstanceKlass::cast(this_oop->pool_holder())->class_loader_data();
+        ClassLoaderData* this_key = this_oop->pool_holder()->class_loader_data();
         if (!this_key->is_the_null_class_loader_data()) {
           this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM
         }
@@ -367,8 +367,8 @@
     assert(entry.is_unresolved(), "must be either symbol or klass");
     Thread *thread = Thread::current();
     Symbol* name = entry.get_symbol();
-    oop loader = InstanceKlass::cast(this_oop->pool_holder())->class_loader();
-    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
+    oop loader = this_oop->pool_holder()->class_loader();
+    oop protection_domain = this_oop->pool_holder()->protection_domain();
     Handle h_prot (thread, protection_domain);
     Handle h_loader (thread, loader);
     Klass* k = SystemDictionary::find(name, h_loader, h_prot, thread);
@@ -409,8 +409,8 @@
   } else {
     assert(entry.is_unresolved(), "must be either symbol or klass");
     Symbol*  name  = entry.get_symbol();
-    oop loader = InstanceKlass::cast(this_oop->pool_holder())->class_loader();
-    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
+    oop loader = this_oop->pool_holder()->class_loader();
+    oop protection_domain = this_oop->pool_holder()->protection_domain();
     Handle h_loader(THREAD, loader);
     Handle h_prot  (THREAD, protection_domain);
     KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD));
@@ -1790,7 +1790,7 @@
     assert(cp_patches->at(index).is_null(),
            err_msg("Unused constant pool patch at %d in class file %s",
                    index,
-                   InstanceKlass::cast(pool_holder())->external_name()));
+                   pool_holder()->external_name()));
   }
 #endif // ASSERT
 }
@@ -1948,7 +1948,7 @@
   st->print(" for ");
   pool_holder()->print_value_on(st);
   if (pool_holder() != NULL) {
-    bool extra = (InstanceKlass::cast(pool_holder())->constants() != this);
+    bool extra = (pool_holder()->constants() != this);
     if (extra)  st->print(" (extra)");
   }
   if (cache() != NULL) {
--- a/src/share/vm/oops/constantPool.hpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/constantPool.hpp	Fri Nov 09 16:45:20 2012 -0800
@@ -86,8 +86,8 @@
   friend class Universe;             // For null constructor
  private:
   Array<u1>*           _tags;        // the tag array describing the constant pool's contents
-  ConstantPoolCache* _cache;       // the cache holding interpreter runtime information
-  Klass*               _pool_holder; // the corresponding class
+  ConstantPoolCache*   _cache;       // the cache holding interpreter runtime information
+  InstanceKlass*       _pool_holder; // the corresponding class
   Array<u2>*           _operands;    // for variable-sized (InvokeDynamic) nodes, usually empty
 
   // Array of resolved objects from the constant pool and map from resolved
@@ -193,9 +193,9 @@
   void set_on_stack(const bool value);
 
   // Klass holding pool
-  Klass* pool_holder() const              { return _pool_holder; }
-  void set_pool_holder(Klass* k)          { _pool_holder = k; }
-  Klass** pool_holder_addr()              { return &_pool_holder; }
+  InstanceKlass* pool_holder() const      { return _pool_holder; }
+  void set_pool_holder(InstanceKlass* k)  { _pool_holder = k; }
+  InstanceKlass** pool_holder_addr()      { return &_pool_holder; }
 
   // Interpreter runtime support
   ConstantPoolCache* cache() const        { return _cache; }
--- a/src/share/vm/oops/cpCache.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/cpCache.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -231,8 +231,8 @@
 
 
 void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index) {
-  Klass* interf = method->method_holder();
-  assert(InstanceKlass::cast(interf)->is_interface(), "must be an interface");
+  InstanceKlass* interf = method->method_holder();
+  assert(interf->is_interface(), "must be an interface");
   assert(!method->is_final_method(), "interfaces do not have final methods; cannot link to one here");
   set_f1(interf);
   set_f2(index);
@@ -421,7 +421,7 @@
         if (!(*trace_name_printed)) {
           // RC_TRACE_MESG macro has an embedded ResourceMark
           RC_TRACE_MESG(("adjust: name=%s",
-            Klass::cast(old_method->method_holder())->external_name()));
+            old_method->method_holder()->external_name()));
           *trace_name_printed = true;
         }
         // RC_TRACE macro has an embedded ResourceMark
@@ -449,7 +449,7 @@
       if (!(*trace_name_printed)) {
         // RC_TRACE_MESG macro has an embedded ResourceMark
         RC_TRACE_MESG(("adjust: name=%s",
-          Klass::cast(old_method->method_holder())->external_name()));
+          old_method->method_holder()->external_name()));
         *trace_name_printed = true;
       }
       // RC_TRACE macro has an embedded ResourceMark
--- a/src/share/vm/oops/klassVtable.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/klassVtable.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -307,7 +307,7 @@
     if (super_method->name() == name && super_method->signature() == signature) {
 
       // get super_klass for method_holder for the found method
-      InstanceKlass* super_klass =  InstanceKlass::cast(super_method->method_holder());
+      InstanceKlass* super_klass =  super_method->method_holder();
 
       if ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) ||
       ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION)
@@ -452,7 +452,7 @@
     }
     // get the class holding the matching method
     // make sure you use that class for is_override
-    InstanceKlass* superk = InstanceKlass::cast(super_method->method_holder());
+    InstanceKlass* superk = super_method->method_holder();
     // we want only instance method matches
     // pretend private methods are not in the super vtable
     // since we do override around them: e.g. a.m pub/b.m private/c.m pub,
@@ -630,7 +630,7 @@
           if (!(*trace_name_printed)) {
             // RC_TRACE_MESG macro has an embedded ResourceMark
             RC_TRACE_MESG(("adjust: name=%s",
-                           Klass::cast(old_method->method_holder())->external_name()));
+                           old_method->method_holder()->external_name()));
             *trace_name_printed = true;
           }
           // RC_TRACE macro has an embedded ResourceMark
@@ -745,7 +745,7 @@
     Method* target = klass->uncached_lookup_method(method_name, method_signature);
     while (target != NULL && target->is_static()) {
       // continue with recursive lookup through the superclass
-      Klass* super = Klass::cast(target->method_holder())->super();
+      Klass* super = target->method_holder()->super();
       target = (super == NULL) ? (Method*)NULL : Klass::cast(super)->uncached_lookup_method(method_name, method_signature);
     }
     if (target == NULL || !target->is_public() || target->is_abstract()) {
@@ -755,7 +755,7 @@
       // if checkconstraints requested
       methodHandle  target_h (THREAD, target); // preserve across gc
       if (checkconstraints) {
-        Handle method_holder_loader (THREAD, InstanceKlass::cast(target->method_holder())->class_loader());
+        Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
         if (method_holder_loader() != interface_loader()) {
           ResourceMark rm(THREAD);
           char* failed_type_name =
@@ -825,7 +825,7 @@
           if (!(*trace_name_printed)) {
             // RC_TRACE_MESG macro has an embedded ResourceMark
             RC_TRACE_MESG(("adjust: name=%s",
-              Klass::cast(old_method->method_holder())->external_name()));
+              old_method->method_holder()->external_name()));
             *trace_name_printed = true;
           }
           // RC_TRACE macro has an embedded ResourceMark
@@ -960,9 +960,9 @@
 
 // m must be a method in an interface
 int klassItable::compute_itable_index(Method* m) {
-  Klass* intf = m->method_holder();
-  assert(InstanceKlass::cast(intf)->is_interface(), "sanity check");
-  Array<Method*>* methods = InstanceKlass::cast(intf)->methods();
+  InstanceKlass* intf = m->method_holder();
+  assert(intf->is_interface(), "sanity check");
+  Array<Method*>* methods = intf->methods();
   int index = 0;
   while(methods->at(index) != m) {
     index++;
--- a/src/share/vm/oops/method.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/method.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -243,12 +243,12 @@
       warning("oopmap should only be accessed by the "
               "VM, GC task or CMS threads (or during debugging)");
       InterpreterOopMap local_mask;
-      InstanceKlass::cast(method_holder())->mask_for(h_this, bci, &local_mask);
+      method_holder()->mask_for(h_this, bci, &local_mask);
       local_mask.print();
     }
   }
 #endif
-  InstanceKlass::cast(method_holder())->mask_for(h_this, bci, mask);
+  method_holder()->mask_for(h_this, bci, mask);
   return;
 }
 
@@ -523,7 +523,7 @@
 bool Method::is_final_method() const {
   // %%% Should return true for private methods also,
   // since there is no way to override them.
-  return is_final() || Klass::cast(method_holder())->is_final();
+  return is_final() || method_holder()->is_final();
 }
 
 
@@ -555,7 +555,7 @@
 
 bool Method::has_valid_initializer_flags() const {
   return (is_static() ||
-          InstanceKlass::cast(method_holder())->major_version() < 51);
+          method_holder()->major_version() < 51);
 }
 
 bool Method::is_static_initializer() const {
@@ -617,7 +617,7 @@
   if( constants()->tag_at(klass_index).is_unresolved_klass() ) {
     Thread *thread = Thread::current();
     Symbol* klass_name = constants()->klass_name_at(klass_index);
-    Handle loader(thread, InstanceKlass::cast(method_holder())->class_loader());
+    Handle loader(thread, method_holder()->class_loader());
     Handle prot  (thread, Klass::cast(method_holder())->protection_domain());
     return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
   } else {
@@ -935,7 +935,7 @@
 
   // If method is an interface, we skip it - except if it
   // is a miranda method
-  if (InstanceKlass::cast(method_holder())->is_interface()) {
+  if (method_holder()->is_interface()) {
     // Check that method is not a miranda method
     if (ik->lookup_method(name(), signature()) == NULL) {
       // No implementation exist - so miranda method
@@ -1020,7 +1020,7 @@
     ConstantPool* cp_oop = ConstantPool::allocate(loader_data, cp_length, CHECK_(empty));
     cp = constantPoolHandle(THREAD, cp_oop);
   }
-  cp->set_pool_holder(holder());
+  cp->set_pool_holder(InstanceKlass::cast(holder()));
   cp->symbol_at_put(_imcp_invoke_name,       name);
   cp->symbol_at_put(_imcp_invoke_signature,  signature);
   cp->set_preresolution();
@@ -1237,8 +1237,8 @@
     return false;
   }
   bool sig_is_loaded = true;
-  Handle class_loader(THREAD, InstanceKlass::cast(m->method_holder())->class_loader());
-  Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain());
+  Handle class_loader(THREAD, m->method_holder()->class_loader());
+  Handle protection_domain(THREAD, m->method_holder()->protection_domain());
   ResourceMark rm(THREAD);
   Symbol*  signature = m->signature();
   for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
@@ -1264,8 +1264,8 @@
 }
 
 bool Method::has_unloaded_classes_in_signature(methodHandle m, TRAPS) {
-  Handle class_loader(THREAD, InstanceKlass::cast(m->method_holder())->class_loader());
-  Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain());
+  Handle class_loader(THREAD, m->method_holder()->class_loader());
+  Handle protection_domain(THREAD, m->method_holder()->protection_domain());
   ResourceMark rm(THREAD);
   Symbol*  signature = m->signature();
   for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
@@ -1472,7 +1472,7 @@
 
 
 Bytecodes::Code Method::orig_bytecode_at(int bci) const {
-  BreakpointInfo* bp = InstanceKlass::cast(method_holder())->breakpoints();
+  BreakpointInfo* bp = method_holder()->breakpoints();
   for (; bp != NULL; bp = bp->next()) {
     if (bp->match(this, bci)) {
       return bp->orig_bytecode();
@@ -1484,7 +1484,7 @@
 
 void Method::set_orig_bytecode_at(int bci, Bytecodes::Code code) {
   assert(code != Bytecodes::_breakpoint, "cannot patch breakpoints this way");
-  BreakpointInfo* bp = InstanceKlass::cast(method_holder())->breakpoints();
+  BreakpointInfo* bp = method_holder()->breakpoints();
   for (; bp != NULL; bp = bp->next()) {
     if (bp->match(this, bci)) {
       bp->set_orig_bytecode(code);
@@ -1494,7 +1494,7 @@
 }
 
 void Method::set_breakpoint(int bci) {
-  InstanceKlass* ik = InstanceKlass::cast(method_holder());
+  InstanceKlass* ik = method_holder();
   BreakpointInfo *bp = new BreakpointInfo(this, bci);
   bp->set_next(ik->breakpoints());
   ik->set_breakpoints(bp);
@@ -1503,7 +1503,7 @@
 }
 
 static void clear_matches(Method* m, int bci) {
-  InstanceKlass* ik = InstanceKlass::cast(m->method_holder());
+  InstanceKlass* ik = m->method_holder();
   BreakpointInfo* prev_bp = NULL;
   BreakpointInfo* next_bp;
   for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = next_bp) {
@@ -1786,7 +1786,7 @@
 bool Method::is_method_id(jmethodID mid) {
   Method* m = resolve_jmethod_id(mid);
   assert(m != NULL, "should be called with non-null method");
-  InstanceKlass* ik = InstanceKlass::cast(m->method_holder());
+  InstanceKlass* ik = m->method_holder();
   ClassLoaderData* cld = ik->class_loader_data();
   if (cld->jmethod_ids() == NULL) return false;
   return (cld->jmethod_ids()->contains((Method**)mid));
--- a/src/share/vm/oops/method.hpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/oops/method.hpp	Fri Nov 09 16:45:20 2012 -0800
@@ -209,21 +209,21 @@
 
   // annotations support
   AnnotationArray* annotations() const           {
-    InstanceKlass* ik = InstanceKlass::cast(method_holder());
+    InstanceKlass* ik = method_holder();
     if (ik->annotations() == NULL) {
       return NULL;
     }
     return ik->annotations()->get_method_annotations_of(method_idnum());
   }
   AnnotationArray* parameter_annotations() const {
-    InstanceKlass* ik = InstanceKlass::cast(method_holder());
+    InstanceKlass* ik = method_holder();
     if (ik->annotations() == NULL) {
       return NULL;
     }
     return ik->annotations()->get_method_parameter_annotations_of(method_idnum());
   }
   AnnotationArray* annotation_default() const    {
-    InstanceKlass* ik = InstanceKlass::cast(method_holder());
+    InstanceKlass* ik = method_holder();
     if (ik->annotations() == NULL) {
       return NULL;
     }
@@ -496,7 +496,7 @@
                        { return constMethod()->compressed_linenumber_table(); }
 
   // method holder (the Klass* holding this method)
-  Klass* method_holder() const                 { return constants()->pool_holder(); }
+  InstanceKlass* method_holder() const         { return constants()->pool_holder(); }
 
   void compute_size_of_parameters(Thread *thread); // word size of parameters (receiver if any + arguments)
   Symbol* klass_name() const;                    // returns the name of the method holder
@@ -697,18 +697,18 @@
 
   // Get this method's jmethodID -- allocate if it doesn't exist
   jmethodID jmethod_id()                            { methodHandle this_h(this);
-                                                      return InstanceKlass::get_jmethod_id(InstanceKlass::cast(method_holder()), this_h); }
+                                                      return InstanceKlass::get_jmethod_id(method_holder(), this_h); }
 
   // Lookup the jmethodID for this method.  Return NULL if not found.
   // NOTE that this function can be called from a signal handler
   // (see AsyncGetCallTrace support for Forte Analyzer) and this
   // needs to be async-safe. No allocation should be done and
   // so handles are not used to avoid deadlock.
-  jmethodID find_jmethod_id_or_null()               { return InstanceKlass::cast(method_holder())->jmethod_id_or_null(this); }
+  jmethodID find_jmethod_id_or_null()               { return method_holder()->jmethod_id_or_null(this); }
 
   // JNI static invoke cached itable index accessors
-  int cached_itable_index()                         { return InstanceKlass::cast(method_holder())->cached_itable_index(method_idnum()); }
-  void set_cached_itable_index(int index)           { InstanceKlass::cast(method_holder())->set_cached_itable_index(method_idnum(), index); }
+  int cached_itable_index()                         { return method_holder()->cached_itable_index(method_idnum()); }
+  void set_cached_itable_index(int index)           { method_holder()->set_cached_itable_index(method_idnum(), index); }
 
   // Support for inlining of intrinsic methods
   vmIntrinsics::ID intrinsic_id() const          { return (vmIntrinsics::ID) _intrinsic_id;           }
@@ -734,11 +734,11 @@
 
   // On-stack replacement support
   bool has_osr_nmethod(int level, bool match_level) {
-   return InstanceKlass::cast(method_holder())->lookup_osr_nmethod(this, InvocationEntryBci, level, match_level) != NULL;
+   return method_holder()->lookup_osr_nmethod(this, InvocationEntryBci, level, match_level) != NULL;
   }
 
   nmethod* lookup_osr_nmethod_for(int bci, int level, bool match_level) {
-    return InstanceKlass::cast(method_holder())->lookup_osr_nmethod(this, bci, level, match_level);
+    return method_holder()->lookup_osr_nmethod(this, bci, level, match_level);
   }
 
   // Inline cache support
--- a/src/share/vm/prims/jni.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/prims/jni.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -2985,7 +2985,7 @@
   }
 
   // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
-  JNIid* id = InstanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset());
+  JNIid* id = fd.field_holder()->jni_id_for(fd.offset());
   debug_only(id->set_is_static_field_id();)
 
   debug_only(id->verify(fd.field_holder()));
@@ -4016,7 +4016,7 @@
   if (PrintJNIResolving) {
     ResourceMark rm(THREAD);
     tty->print_cr("[Registering JNI native method %s.%s]",
-      Klass::cast(method->method_holder())->external_name(),
+      method->method_holder()->external_name(),
       method->name()->as_C_string());
   }
   return true;
--- a/src/share/vm/prims/jvm.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/prims/jvm.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -125,7 +125,7 @@
   int line_number = -1;
   const char * source_file = NULL;
   const char * trace = "explicit";
-  Klass* caller = NULL;
+  InstanceKlass* caller = NULL;
   JavaThread* jthread = JavaThread::current();
   if (jthread->has_last_Java_frame()) {
     vframeStream vfst(jthread);
@@ -153,17 +153,17 @@
     // that caller, otherwise keep quiet since this should be picked up elsewhere.
     bool found_it = false;
     if (!vfst.at_end() &&
-        InstanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class() &&
+        vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
         vfst.method()->name() == vmSymbols::forName0_name()) {
       vfst.next();
       if (!vfst.at_end() &&
-          InstanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class() &&
+          vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
           vfst.method()->name() == vmSymbols::forName_name()) {
         vfst.next();
         found_it = true;
       }
     } else if (last_caller != NULL &&
-               InstanceKlass::cast(last_caller->method_holder())->name() ==
+               last_caller->method_holder()->name() ==
                vmSymbols::java_lang_ClassLoader() &&
                (last_caller->name() == vmSymbols::loadClassInternal_name() ||
                 last_caller->name() == vmSymbols::loadClass_name())) {
@@ -182,7 +182,7 @@
         // show method name if it's a native method
         trace = vfst.method()->name_and_sig_as_C_string();
       }
-      Symbol* s = InstanceKlass::cast(caller)->source_file_name();
+      Symbol* s = caller->source_file_name();
       if (s != NULL) {
         source_file = s->as_C_string();
       }
@@ -190,8 +190,8 @@
   }
   if (caller != NULL) {
     if (to_class != caller) {
-      const char * from = Klass::cast(caller)->external_name();
-      const char * to = Klass::cast(to_class)->external_name();
+      const char * from = caller->external_name();
+      const char * to = to_class->external_name();
       // print in a single call to reduce interleaving between threads
       if (source_file != NULL) {
         tty->print("RESOLVE %s %s %s:%d (%s)\n", from, to, source_file, line_number, trace);
@@ -1228,7 +1228,7 @@
       privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
       protection_domain  = thread->privileged_stack_top()->protection_domain();
     } else {
-      protection_domain = InstanceKlass::cast(method->method_holder())->protection_domain();
+      protection_domain = method->method_holder()->protection_domain();
     }
 
     if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
@@ -3048,10 +3048,10 @@
 
     Method* m = vfst.method();
     if (!m->is_native()) {
-      Klass* holder = m->method_holder();
-      oop      loader = InstanceKlass::cast(holder)->class_loader();
+      InstanceKlass* holder = m->method_holder();
+      oop loader = holder->class_loader();
       if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
-        return (jclass) JNIHandles::make_local(env, Klass::cast(holder)->java_mirror());
+        return (jclass) JNIHandles::make_local(env, holder->java_mirror());
       }
     }
   }
@@ -3071,9 +3071,9 @@
 
     Method* m = vfst.method();
     if (!m->is_native()) {
-      Klass* holder = m->method_holder();
+      InstanceKlass* holder = m->method_holder();
       assert(holder->is_klass(), "just checking");
-      oop loader = InstanceKlass::cast(holder)->class_loader();
+      oop loader = holder->class_loader();
       if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
         return JNIHandles::make_local(env, loader);
       }
@@ -3148,9 +3148,9 @@
 
   for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
     if (!vfst.method()->is_native()) {
-      Klass* holder = vfst.method()->method_holder();
+      InstanceKlass* holder = vfst.method()->method_holder();
       assert(holder->is_klass(), "just checking");
-      if (InstanceKlass::cast(holder)->name() == class_name_sym) {
+      if (holder->name() == class_name_sym) {
         return depth;
       }
       depth++;
@@ -3171,9 +3171,9 @@
 
     Method* m = vfst.method();
     if (!m->is_native()) {
-      Klass* holder = m->method_holder();
+      InstanceKlass* holder = m->method_holder();
       assert(holder->is_klass(), "just checking");
-      oop loader = InstanceKlass::cast(holder)->class_loader();
+      oop loader = holder->class_loader();
       if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
         return depth;
       }
@@ -3322,8 +3322,7 @@
   for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
     // UseNewReflection
     vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection
-    Klass* holder = vfst.method()->method_holder();
-    oop loader = InstanceKlass::cast(holder)->class_loader();
+    oop loader = vfst.method()->method_holder()->class_loader();
     if (loader != NULL) {
       return JNIHandles::make_local(env, loader);
     }
@@ -3365,9 +3364,9 @@
          !vfst.at_end() && loader == NULL;
          vfst.next()) {
       if (!vfst.method()->is_native()) {
-        Klass* holder = vfst.method()->method_holder();
-        loader             = InstanceKlass::cast(holder)->class_loader();
-        protection_domain  = InstanceKlass::cast(holder)->protection_domain();
+        InstanceKlass* holder = vfst.method()->method_holder();
+        loader             = holder->class_loader();
+        protection_domain  = holder->protection_domain();
       }
     }
   } else {
--- a/src/share/vm/prims/jvmtiClassFileReconstituter.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/prims/jvmtiClassFileReconstituter.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -228,7 +228,7 @@
 
   write_attribute_name_index("Code");
   write_u4(size);
-  write_u2(method->max_stack());
+  write_u2(method->verifier_max_stack());
   write_u2(method->max_locals());
   write_u4(code_size);
   copy_bytecodes(method, (unsigned char*)writeable_address(code_size));
@@ -753,7 +753,7 @@
 
   unsigned char* p = bytecodes;
   Bytecodes::Code code;
-  bool is_rewritten = InstanceKlass::cast(mh->method_holder())->is_rewritten();
+  bool is_rewritten = mh->method_holder()->is_rewritten();
 
   while ((code = bs.next()) >= 0) {
     assert(Bytecodes::is_java_code(code), "sanity check");
--- a/src/share/vm/prims/jvmtiEnv.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/prims/jvmtiEnv.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -2822,7 +2822,7 @@
   JavaThread* current_thread  = JavaThread::current();
 
   // does the klass have any local variable information?
-  InstanceKlass* ik = InstanceKlass::cast(method_oop->method_holder());
+  InstanceKlass* ik = method_oop->method_holder();
   if (!ik->access_flags().has_localvariable_table()) {
     return (JVMTI_ERROR_ABSENT_INFORMATION);
   }
--- a/src/share/vm/prims/methodHandles.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/prims/methodHandles.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -233,7 +233,7 @@
   methodHandle m = info.resolved_method();
   KlassHandle defc = info.resolved_klass();
   int vmindex = -1;
-  if (defc->is_interface() && Klass::cast(m->method_holder())->is_interface()) {
+  if (defc->is_interface() && m->method_holder()->is_interface()) {
     // LinkResolver does not report itable indexes!  (fix this?)
     vmindex = klassItable::compute_itable_index(m());
   } else if (m->can_be_statically_bound()) {
@@ -749,8 +749,8 @@
       DEBUG_ONLY(vmtarget = NULL);  // safety
       if (m.is_null())  break;
       if (!have_defc) {
-        Klass* defc = m->method_holder();
-        java_lang_invoke_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror());
+        InstanceKlass* defc = m->method_holder();
+        java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
       }
       if (!have_name) {
         //not java_lang_String::create_from_symbol; let's intern member names
--- a/src/share/vm/prims/nativeLookup.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/prims/nativeLookup.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -165,8 +165,7 @@
   // Note: It is critical for bootstrapping that Java_java_lang_ClassLoader_00024NativeLibrary_find
   // gets found the first time around - otherwise an infinite loop can occure. This is
   // another VM/library dependency
-  Handle loader(THREAD,
-                InstanceKlass::cast(method->method_holder())->class_loader());
+  Handle loader(THREAD, method->method_holder()->class_loader());
   if (loader.is_null()) {
     entry = lookup_special_native(jni_name);
     if (entry == NULL) {
@@ -393,7 +392,7 @@
     if (PrintJNIResolving) {
       ResourceMark rm(THREAD);
       tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
-        Klass::cast(method->method_holder())->external_name(),
+        method->method_holder()->external_name(),
         method->name()->as_C_string());
     }
   }
--- a/src/share/vm/runtime/compilationPolicy.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/compilationPolicy.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -627,7 +627,7 @@
   // negative filter: should send NOT be inlined?  returns NULL (--> inline) or rejection msg
   if (m->is_abstract()) return (_msg = "abstract method");
   // note: we allow ik->is_abstract()
-  if (!InstanceKlass::cast(m->method_holder())->is_initialized()) return (_msg = "method holder not initialized");
+  if (!m->method_holder()->is_initialized()) return (_msg = "method holder not initialized");
   if (m->is_native()) return (_msg = "native method");
   nmethod* m_code = m->code();
   if (m_code != NULL && m_code->code_size() > InlineSmallCode)
--- a/src/share/vm/runtime/deoptimization.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/deoptimization.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1191,12 +1191,12 @@
 
   if (!constant_pool->tag_at(index).is_symbol()) return;
 
-  Handle class_loader (THREAD, InstanceKlass::cast(constant_pool->pool_holder())->class_loader());
+  Handle class_loader (THREAD, constant_pool->pool_holder()->class_loader());
   Symbol*  symbol  = constant_pool->symbol_at(index);
 
   // class name?
   if (symbol->byte_at(0) != '(') {
-    Handle protection_domain (THREAD, Klass::cast(constant_pool->pool_holder())->protection_domain());
+    Handle protection_domain (THREAD, constant_pool->pool_holder()->protection_domain());
     SystemDictionary::resolve_or_null(symbol, class_loader, protection_domain, CHECK);
     return;
   }
@@ -1206,7 +1206,7 @@
   for (SignatureStream ss(symbol); !ss.is_done(); ss.next()) {
     if (ss.is_object()) {
       Symbol* class_name = ss.as_symbol(CHECK);
-      Handle protection_domain (THREAD, Klass::cast(constant_pool->pool_holder())->protection_domain());
+      Handle protection_domain (THREAD, constant_pool->pool_holder()->protection_domain());
       SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK);
     }
   }
--- a/src/share/vm/runtime/fieldDescriptor.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/fieldDescriptor.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -36,7 +36,7 @@
 
 
 oop fieldDescriptor::loader() const {
-  return InstanceKlass::cast(_cp->pool_holder())->class_loader();
+  return _cp->pool_holder()->class_loader();
 }
 
 Symbol* fieldDescriptor::generic_signature() const {
@@ -45,7 +45,7 @@
   }
 
   int idx = 0;
-  InstanceKlass* ik = InstanceKlass::cast(field_holder());
+  InstanceKlass* ik = field_holder();
   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
     if (idx == _index) {
       return fs.generic_signature();
@@ -58,7 +58,7 @@
 }
 
 AnnotationArray* fieldDescriptor::annotations() const {
-  InstanceKlass* ik = InstanceKlass::cast(field_holder());
+  InstanceKlass* ik = field_holder();
   Array<AnnotationArray*>* md = ik->fields_annotations();
   if (md == NULL)
     return NULL;
--- a/src/share/vm/runtime/fieldDescriptor.hpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/fieldDescriptor.hpp	Fri Nov 09 16:45:20 2012 -0800
@@ -43,12 +43,12 @@
 
   // update the access_flags for the field in the klass
   void update_klass_field_access_flag() {
-    InstanceKlass* ik = InstanceKlass::cast(field_holder());
+    InstanceKlass* ik = field_holder();
     ik->field(index())->set_access_flags(_access_flags.as_short());
   }
 
   FieldInfo* field() const {
-    InstanceKlass* ik = InstanceKlass::cast(field_holder());
+    InstanceKlass* ik = field_holder();
     return ik->field(_index);
   }
 
@@ -59,46 +59,46 @@
   Symbol* signature() const {
     return field()->signature(_cp);
   }
-  Klass* field_holder() const        { return _cp->pool_holder(); }
-  ConstantPool* constants() const    { return _cp(); }
-  AccessFlags access_flags() const     { return _access_flags; }
-  oop loader() const;
+  InstanceKlass* field_holder()   const    { return _cp->pool_holder(); }
+  ConstantPool* constants()       const    { return _cp(); }
+  AccessFlags access_flags()      const    { return _access_flags; }
+  oop loader()                    const;
   // Offset (in words) of field from start of instanceOop / Klass*
-  int offset() const                   { return field()->offset(); }
-  Symbol* generic_signature() const;
-  int index() const                    { return _index; }
-  AnnotationArray* annotations() const;
+  int offset()                    const    { return field()->offset(); }
+  Symbol* generic_signature()     const;
+  int index()                     const    { return _index; }
+  AnnotationArray* annotations()  const;
 
   // Initial field value
-  bool has_initial_value() const          { return field()->initval_index() != 0; }
-  int initial_value_index() const         { return field()->initval_index(); }
+  bool has_initial_value()        const    { return field()->initval_index() != 0; }
+  int initial_value_index()       const    { return field()->initval_index(); }
   constantTag initial_value_tag() const;  // The tag will return true on one of is_int(), is_long(), is_single(), is_double()
-  jint        int_initial_value() const;
-  jlong       long_initial_value() const;
-  jfloat      float_initial_value() const;
-  jdouble     double_initial_value() const;
-  oop         string_initial_value(TRAPS) const;
+  jint int_initial_value()        const;
+  jlong long_initial_value()      const;
+  jfloat float_initial_value()    const;
+  jdouble double_initial_value()  const;
+  oop string_initial_value(TRAPS) const;
 
   // Field signature type
-  BasicType field_type() const            { return FieldType::basic_type(signature()); }
+  BasicType field_type()          const    { return FieldType::basic_type(signature()); }
 
   // Access flags
-  bool is_public() const                  { return access_flags().is_public(); }
-  bool is_private() const                 { return access_flags().is_private(); }
-  bool is_protected() const               { return access_flags().is_protected(); }
-  bool is_package_private() const         { return !is_public() && !is_private() && !is_protected(); }
+  bool is_public()                const    { return access_flags().is_public(); }
+  bool is_private()               const    { return access_flags().is_private(); }
+  bool is_protected()             const    { return access_flags().is_protected(); }
+  bool is_package_private()       const    { return !is_public() && !is_private() && !is_protected(); }
 
-  bool is_static() const                  { return access_flags().is_static(); }
-  bool is_final() const                   { return access_flags().is_final(); }
-  bool is_volatile() const                { return access_flags().is_volatile(); }
-  bool is_transient() const               { return access_flags().is_transient(); }
+  bool is_static()                const    { return access_flags().is_static(); }
+  bool is_final()                 const    { return access_flags().is_final(); }
+  bool is_volatile()              const    { return access_flags().is_volatile(); }
+  bool is_transient()             const    { return access_flags().is_transient(); }
 
-  bool is_synthetic() const               { return access_flags().is_synthetic(); }
+  bool is_synthetic()             const    { return access_flags().is_synthetic(); }
 
-  bool is_field_access_watched() const    { return access_flags().is_field_access_watched(); }
+  bool is_field_access_watched()  const    { return access_flags().is_field_access_watched(); }
   bool is_field_modification_watched() const
-                                          { return access_flags().is_field_modification_watched(); }
-  bool has_generic_signature() const      { return access_flags().field_has_generic_signature(); }
+                                           { return access_flags().is_field_modification_watched(); }
+  bool has_generic_signature()    const    { return access_flags().field_has_generic_signature(); }
 
   void set_is_field_access_watched(const bool value) {
     _access_flags.set_is_field_access_watched(value);
--- a/src/share/vm/runtime/javaCalls.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/javaCalls.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -189,7 +189,7 @@
   assert(method->name() == vmSymbols::object_initializer_name(),    "Should only be called for default constructor");
   assert(method->signature() == vmSymbols::void_method_signature(), "Should only be called for default constructor");
 
-  InstanceKlass* ik = InstanceKlass::cast(method->method_holder());
+  InstanceKlass* ik = method->method_holder();
   if (ik->is_initialized() && ik->has_vanilla_constructor()) {
     // safe to skip constructor call
   } else {
@@ -344,11 +344,11 @@
 
 
 #ifdef ASSERT
-  { Klass* holder = method->method_holder();
+  { InstanceKlass* holder = method->method_holder();
     // A klass might not be initialized since JavaCall's might be used during the executing of
     // the <clinit>. For example, a Thread.start might start executing on an object that is
     // not fully initialized! (bad Java programming style)
-    assert(InstanceKlass::cast(holder)->is_linked(), "rewritting must have taken place");
+    assert(holder->is_linked(), "rewritting must have taken place");
   }
 #endif
 
--- a/src/share/vm/runtime/mutexLocker.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/mutexLocker.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -140,6 +140,7 @@
 Monitor* JfrMsg_lock                  = NULL;
 Mutex*   JfrBuffer_lock               = NULL;
 Mutex*   JfrStream_lock               = NULL;
+Monitor* PeriodicTask_lock            = NULL;
 
 #define MAX_NUM_MUTEX 128
 static Monitor * _mutex_array[MAX_NUM_MUTEX];
@@ -285,6 +286,7 @@
   def(JfrMsg_lock                  , Monitor, nonleaf+2,   true);
   def(JfrBuffer_lock               , Mutex,   nonleaf+3,   true);
   def(JfrStream_lock               , Mutex,   nonleaf+4,   true);
+  def(PeriodicTask_lock            , Monitor, nonleaf+5,   true);
 }
 
 GCMutexLocker::GCMutexLocker(Monitor * mutex) {
--- a/src/share/vm/runtime/mutexLocker.hpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/mutexLocker.hpp	Fri Nov 09 16:45:20 2012 -0800
@@ -142,6 +142,7 @@
 extern Monitor* JfrMsg_lock;                     // protects JFR messaging
 extern Mutex*   JfrBuffer_lock;                  // protects JFR buffer operations
 extern Mutex*   JfrStream_lock;                  // protects JFR stream access
+extern Monitor* PeriodicTask_lock;               // protects the periodic task structure
 
 // A MutexLocker provides mutual exclusion with respect to a given mutex
 // for the scope which contains the locker.  The lock is an OS lock, not
--- a/src/share/vm/runtime/reflection.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/reflection.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -56,14 +56,14 @@
     vframeStream vfst(jthread);
     // skip over any frames belonging to java.lang.Class
     while (!vfst.at_end() &&
-           InstanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class()) {
+           vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class()) {
       vfst.next();
     }
     if (!vfst.at_end()) {
       // this frame is a likely suspect
       caller = vfst.method()->method_holder();
       line_number = vfst.method()->line_number_from_bci(vfst.bci());
-      Symbol* s = InstanceKlass::cast(vfst.method()->method_holder())->source_file_name();
+      Symbol* s = vfst.method()->method_holder()->source_file_name();
       if (s != NULL) {
         source_file = s->as_C_string();
       }
@@ -642,8 +642,8 @@
     case T_OBJECT:
     case T_ARRAY:
       Symbol* name        = ss->as_symbol(CHECK_NULL);
-      oop loader            = InstanceKlass::cast(method->method_holder())->class_loader();
-      oop protection_domain = InstanceKlass::cast(method->method_holder())->protection_domain();
+      oop loader            = method->method_holder()->class_loader();
+      oop protection_domain = method->method_holder()->protection_domain();
       Klass* k = SystemDictionary::resolve_or_fail(
                                        name,
                                        Handle(THREAD, loader),
@@ -714,7 +714,7 @@
   assert(!method()->is_initializer() ||
          (for_constant_pool_access && method()->is_static()) ||
          (method()->name() == vmSymbols::class_initializer_name()
-    && Klass::cast(method()->method_holder())->is_interface() && JDK_Version::is_jdk12x_version()), "should call new_constructor instead");
+    && method()->method_holder()->is_interface() && JDK_Version::is_jdk12x_version()), "should call new_constructor instead");
   instanceKlassHandle holder (THREAD, method->method_holder());
   int slot = method->method_idnum();
 
@@ -832,7 +832,7 @@
   Handle type = new_type(signature, holder, CHECK_NULL);
   Handle rh  = java_lang_reflect_Field::create(CHECK_NULL);
 
-  java_lang_reflect_Field::set_clazz(rh(), Klass::cast(fd->field_holder())->java_mirror());
+  java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
   java_lang_reflect_Field::set_slot(rh(), fd->index());
   java_lang_reflect_Field::set_name(rh(), name());
   java_lang_reflect_Field::set_type(rh(), type());
@@ -900,7 +900,7 @@
       method = reflected_method;
     } else {
       // resolve based on the receiver
-      if (InstanceKlass::cast(reflected_method->method_holder())->is_interface()) {
+      if (reflected_method->method_holder()->is_interface()) {
         // resolve interface call
         if (ReflectionWrapResolutionErrors) {
           // new default: 6531596
--- a/src/share/vm/runtime/task.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/task.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -61,7 +61,7 @@
 }
 #endif
 
-void PeriodicTask::real_time_tick(size_t delay_time) {
+void PeriodicTask::real_time_tick(int delay_time) {
 #ifndef PRODUCT
   if (ProfilerCheckIntervals) {
     _ticks++;
@@ -73,19 +73,39 @@
     _intervalHistogram[ms]++;
   }
 #endif
-  int orig_num_tasks = _num_tasks;
-  for(int index = 0; index < _num_tasks; index++) {
-    _tasks[index]->execute_if_pending(delay_time);
-    if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself
-      index--;  // re-do current slot as it has changed
-      orig_num_tasks = _num_tasks;
+
+  {
+    MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
+    int orig_num_tasks = _num_tasks;
+
+    for(int index = 0; index < _num_tasks; index++) {
+      _tasks[index]->execute_if_pending(delay_time);
+      if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself
+        index--;  // re-do current slot as it has changed
+        orig_num_tasks = _num_tasks;
+      }
     }
   }
 }
 
+int PeriodicTask::time_to_wait() {
+  MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
+                     NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
+
+  if (_num_tasks == 0) {
+    return 0; // sleep until shutdown or a task is enrolled
+  }
+
+  int delay = _tasks[0]->time_to_next_interval();
+  for (int index = 1; index < _num_tasks; index++) {
+    delay = MIN2(delay, _tasks[index]->time_to_next_interval());
+  }
+  return delay;
+}
+
 
 PeriodicTask::PeriodicTask(size_t interval_time) :
-  _counter(0), _interval(interval_time) {
+  _counter(0), _interval((int) interval_time) {
   // Sanity check the interval time
   assert(_interval >= PeriodicTask::min_interval &&
          _interval <= PeriodicTask::max_interval &&
@@ -94,33 +114,40 @@
 }
 
 PeriodicTask::~PeriodicTask() {
-  if (is_enrolled())
-    disenroll();
-}
-
-bool PeriodicTask::is_enrolled() const {
-  for(int index = 0; index < _num_tasks; index++)
-    if (_tasks[index] == this) return true;
-  return false;
+  disenroll();
 }
 
 void PeriodicTask::enroll() {
-  assert(WatcherThread::watcher_thread() == NULL, "dynamic enrollment of tasks not yet supported");
+  MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
+                     NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
 
-  if (_num_tasks == PeriodicTask::max_tasks)
+  if (_num_tasks == PeriodicTask::max_tasks) {
     fatal("Overflow in PeriodicTask table");
+  }
   _tasks[_num_tasks++] = this;
+
+  WatcherThread* thread = WatcherThread::watcher_thread();
+  if (thread) {
+    thread->unpark();
+  } else {
+    WatcherThread::start();
+  }
 }
 
 void PeriodicTask::disenroll() {
-  assert(WatcherThread::watcher_thread() == NULL ||
-         Thread::current() == WatcherThread::watcher_thread(),
-         "dynamic disenrollment currently only handled from WatcherThread from within task() method");
+  MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
+                     NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
 
   int index;
-  for(index = 0; index < _num_tasks && _tasks[index] != this; index++);
-  if (index == _num_tasks) return;
+  for(index = 0; index < _num_tasks && _tasks[index] != this; index++)
+    ;
+
+  if (index == _num_tasks) {
+    return;
+  }
+
   _num_tasks--;
+
   for (; index < _num_tasks; index++) {
     _tasks[index] = _tasks[index+1];
   }
--- a/src/share/vm/runtime/task.hpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/task.hpp	Fri Nov 09 16:45:20 2012 -0800
@@ -49,12 +49,12 @@
   static int num_tasks()   { return _num_tasks; }
 
  private:
-  size_t _counter;
-  const size_t _interval;
+  int _counter;
+  const int _interval;
 
   static int _num_tasks;
   static PeriodicTask* _tasks[PeriodicTask::max_tasks];
-  static void real_time_tick(size_t delay_time);
+  static void real_time_tick(int delay_time);
 
 #ifndef PRODUCT
   static elapsedTimer _timer;                      // measures time between ticks
@@ -69,51 +69,36 @@
   PeriodicTask(size_t interval_time); // interval is in milliseconds of elapsed time
   ~PeriodicTask();
 
-  // Tells whether is enrolled
-  bool is_enrolled() const;
-
   // Make the task active
-  // NOTE: this may only be called before the WatcherThread has been started
+  // For dynamic enrollment at the time T, the task will execute somewhere
+  // between T and T + interval_time.
   void enroll();
 
   // Make the task deactive
-  // NOTE: this may only be called either while the WatcherThread is
-  // inactive or by a task from within its task() method. One-shot or
-  // several-shot tasks may be implemented this way.
   void disenroll();
 
-  void execute_if_pending(size_t delay_time) {
-    _counter += delay_time;
-    if (_counter >= _interval) {
+  void execute_if_pending(int delay_time) {
+    // make sure we don't overflow
+    jlong tmp = (jlong) _counter + (jlong) delay_time;
+
+    if (tmp >= (jlong) _interval) {
       _counter = 0;
       task();
+    } else {
+      _counter += delay_time;
     }
   }
 
   // Returns how long (time in milliseconds) before the next time we should
   // execute this task.
-  size_t time_to_next_interval() const {
+  int time_to_next_interval() const {
     assert(_interval > _counter,  "task counter greater than interval?");
     return _interval - _counter;
   }
 
   // Calculate when the next periodic task will fire.
   // Called by the WatcherThread's run method.
-  // This assumes that periodic tasks aren't entering the system
-  // dynamically, except for during startup.
-  static size_t time_to_wait() {
-    if (_num_tasks == 0) {
-      // Don't wait any more; shut down the thread since we don't
-      // currently support dynamic enrollment.
-      return 0;
-    }
-
-    size_t delay = _tasks[0]->time_to_next_interval();
-    for (int index = 1; index < _num_tasks; index++) {
-      delay = MIN2(delay, _tasks[index]->time_to_next_interval());
-    }
-    return delay;
-  }
+  static int time_to_wait();
 
   // The task to perform at each period
   virtual void task() = 0;
--- a/src/share/vm/runtime/thread.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/thread.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1217,6 +1217,7 @@
 // timer interrupts exists on the platform.
 
 WatcherThread* WatcherThread::_watcher_thread   = NULL;
+bool WatcherThread::_startable = false;
 volatile bool  WatcherThread::_should_terminate = false;
 
 WatcherThread::WatcherThread() : Thread() {
@@ -1237,6 +1238,55 @@
   }
 }
 
+int WatcherThread::sleep() const {
+  MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
+
+  // remaining will be zero if there are no tasks,
+  // causing the WatcherThread to sleep until a task is
+  // enrolled
+  int remaining = PeriodicTask::time_to_wait();
+  int time_slept = 0;
+
+  // we expect this to timeout - we only ever get unparked when
+  // we should terminate or when a new task has been enrolled
+  OSThreadWaitState osts(this->osthread(), false /* not Object.wait() */);
+
+  jlong time_before_loop = os::javaTimeNanos();
+
+  for (;;) {
+    bool timedout = PeriodicTask_lock->wait(Mutex::_no_safepoint_check_flag, remaining);
+    jlong now = os::javaTimeNanos();
+
+    if (remaining == 0) {
+        // if we didn't have any tasks we could have waited for a long time
+        // consider the time_slept zero and reset time_before_loop
+        time_slept = 0;
+        time_before_loop = now;
+    } else {
+        // need to recalulate since we might have new tasks in _tasks
+        time_slept = (int) ((now - time_before_loop) / 1000000);
+    }
+
+    // Change to task list or spurious wakeup of some kind
+    if (timedout || _should_terminate) {
+        break;
+    }
+
+    remaining = PeriodicTask::time_to_wait();
+    if (remaining == 0) {
+        // Last task was just disenrolled so loop around and wait until
+        // another task gets enrolled
+        continue;
+    }
+
+    remaining -= time_slept;
+    if (remaining <= 0)
+      break;
+  }
+
+  return time_slept;
+}
+
 void WatcherThread::run() {
   assert(this == watcher_thread(), "just checking");
 
@@ -1249,26 +1299,7 @@
 
     // Calculate how long it'll be until the next PeriodicTask work
     // should be done, and sleep that amount of time.
-    size_t time_to_wait = PeriodicTask::time_to_wait();
-
-    // we expect this to timeout - we only ever get unparked when
-    // we should terminate
-    {
-      OSThreadWaitState osts(this->osthread(), false /* not Object.wait() */);
-
-      jlong prev_time = os::javaTimeNanos();
-      for (;;) {
-        int res= _SleepEvent->park(time_to_wait);
-        if (res == OS_TIMEOUT || _should_terminate)
-          break;
-        // spurious wakeup of some kind
-        jlong now = os::javaTimeNanos();
-        time_to_wait -= (now - prev_time) / 1000000;
-        if (time_to_wait <= 0)
-          break;
-        prev_time = now;
-      }
-    }
+    int time_waited = sleep();
 
     if (is_error_reported()) {
       // A fatal error has happened, the error handler(VMError::report_and_die)
@@ -1298,13 +1329,7 @@
       }
     }
 
-    PeriodicTask::real_time_tick(time_to_wait);
-
-    // If we have no more tasks left due to dynamic disenrollment,
-    // shut down the thread since we don't currently support dynamic enrollment
-    if (PeriodicTask::num_tasks() == 0) {
-      _should_terminate = true;
-    }
+    PeriodicTask::real_time_tick(time_waited);
   }
 
   // Signal that it is terminated
@@ -1319,22 +1344,33 @@
 }
 
 void WatcherThread::start() {
-  if (watcher_thread() == NULL) {
+  assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
+
+  if (watcher_thread() == NULL && _startable) {
     _should_terminate = false;
     // Create the single instance of WatcherThread
     new WatcherThread();
   }
 }
 
+void WatcherThread::make_startable() {
+  assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
+  _startable = true;
+}
+
 void WatcherThread::stop() {
+  {
+    MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
+    _should_terminate = true;
+    OrderAccess::fence();  // ensure WatcherThread sees update in main loop
+
+    WatcherThread* watcher = watcher_thread();
+    if (watcher != NULL)
+      watcher->unpark();
+  }
+
   // it is ok to take late safepoints here, if needed
   MutexLocker mu(Terminator_lock);
-  _should_terminate = true;
-  OrderAccess::fence();  // ensure WatcherThread sees update in main loop
-
-  Thread* watcher = watcher_thread();
-  if (watcher != NULL)
-    watcher->_SleepEvent->unpark();
 
   while(watcher_thread() != NULL) {
     // This wait should make safepoint checks, wait without a timeout,
@@ -1352,6 +1388,11 @@
   }
 }
 
+void WatcherThread::unpark() {
+  MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ? NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
+  PeriodicTask_lock->notify();
+}
+
 void WatcherThread::print_on(outputStream* st) const {
   st->print("\"%s\" ", name());
   Thread::print_on(st);
@@ -3658,12 +3699,18 @@
     }
   }
 
-  // Start up the WatcherThread if there are any periodic tasks
-  // NOTE:  All PeriodicTasks should be registered by now. If they
-  //   aren't, late joiners might appear to start slowly (we might
-  //   take a while to process their first tick).
-  if (PeriodicTask::num_tasks() > 0) {
-    WatcherThread::start();
+  {
+      MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
+      // Make sure the watcher thread can be started by WatcherThread::start()
+      // or by dynamic enrollment.
+      WatcherThread::make_startable();
+      // Start up the WatcherThread if there are any periodic tasks
+      // NOTE:  All PeriodicTasks should be registered by now. If they
+      //   aren't, late joiners might appear to start slowly (we might
+      //   take a while to process their first tick).
+      if (PeriodicTask::num_tasks() > 0) {
+          WatcherThread::start();
+      }
   }
 
   // Give os specific code one last chance to start
--- a/src/share/vm/runtime/thread.hpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/thread.hpp	Fri Nov 09 16:45:20 2012 -0800
@@ -722,6 +722,7 @@
  private:
   static WatcherThread* _watcher_thread;
 
+  static bool _startable;
   volatile static bool _should_terminate; // updated without holding lock
  public:
   enum SomeConstants {
@@ -738,6 +739,7 @@
   char* name() const { return (char*)"VM Periodic Task Thread"; }
   void print_on(outputStream* st) const;
   void print() const { print_on(tty); }
+  void unpark();
 
   // Returns the single instance of WatcherThread
   static WatcherThread* watcher_thread()         { return _watcher_thread; }
@@ -745,6 +747,12 @@
   // Create and start the single instance of WatcherThread, or stop it on shutdown
   static void start();
   static void stop();
+  // Only allow start once the VM is sufficiently initialized
+  // Otherwise the first task to enroll will trigger the start
+  static void make_startable();
+
+ private:
+  int sleep() const;
 };
 
 
--- a/src/share/vm/runtime/vframe.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/vframe.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -161,7 +161,7 @@
   // If this is the first frame, and java.lang.Object.wait(...) then print out the receiver.
   if (frame_count == 0) {
     if (method()->name() == vmSymbols::wait_name() &&
-        InstanceKlass::cast(method()->method_holder())->name() == vmSymbols::java_lang_Object()) {
+        method()->method_holder()->name() == vmSymbols::java_lang_Object()) {
       StackValueCollection* locs = locals();
       if (!locs->is_empty()) {
         StackValue* sv = locs->at(0);
@@ -407,7 +407,7 @@
     if (Universe::reflect_invoke_cache()->is_same_method(method())) {
       // This is Method.invoke() -- skip it
     } else if (use_new_reflection &&
-              Klass::cast(method()->method_holder())
+              method()->method_holder()
                  ->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass())) {
       // This is an auxilary frame -- skip it
     } else if (method()->is_method_handle_intrinsic() ||
@@ -471,8 +471,8 @@
 void vframeStreamCommon::skip_reflection_related_frames() {
   while (!at_end() &&
          (JDK_Version::is_gte_jdk14x_version() && UseNewReflection &&
-          (Klass::cast(method()->method_holder())->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass()) ||
-           Klass::cast(method()->method_holder())->is_subclass_of(SystemDictionary::reflect_ConstructorAccessorImpl_klass())))) {
+          (method()->method_holder()->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass()) ||
+           method()->method_holder()->is_subclass_of(SystemDictionary::reflect_ConstructorAccessorImpl_klass())))) {
     next();
   }
 }
@@ -547,13 +547,13 @@
 
 void javaVFrame::print_value() const {
   Method*    m = method();
-  Klass*     k = m->method_holder();
+  InstanceKlass*     k = m->method_holder();
   tty->print_cr("frame( sp=" INTPTR_FORMAT ", unextended_sp=" INTPTR_FORMAT ", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT ")",
                 _fr.sp(),  _fr.unextended_sp(), _fr.fp(), _fr.pc());
   tty->print("%s.%s", Klass::cast(k)->internal_name(), m->name()->as_C_string());
 
   if (!m->is_native()) {
-    Symbol*  source_name = InstanceKlass::cast(k)->source_file_name();
+    Symbol*  source_name = k->source_file_name();
     int        line_number = m->line_number_from_bci(bci());
     if (source_name != NULL && (line_number != -1)) {
       tty->print("(%s:%d)", source_name->as_C_string(), line_number);
--- a/src/share/vm/runtime/vmStructs.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/runtime/vmStructs.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -289,7 +289,7 @@
   nonstatic_field(CompiledICHolder,     _holder_klass,                                 Klass*)                                \
   nonstatic_field(ConstantPool,         _tags,                                         Array<u1>*)                            \
   nonstatic_field(ConstantPool,         _cache,                                        ConstantPoolCache*)             \
-  nonstatic_field(ConstantPool,         _pool_holder,                                  Klass*)                                \
+  nonstatic_field(ConstantPool,         _pool_holder,                                  InstanceKlass*)                        \
   nonstatic_field(ConstantPool,         _operands,                                     Array<u2>*)                            \
   nonstatic_field(ConstantPool,         _length,                                       int)                                   \
   nonstatic_field(ConstantPool,         _resolved_references,                          jobject)                               \
--- a/src/share/vm/services/heapDumper.cpp	Fri Nov 09 19:24:31 2012 -0500
+++ b/src/share/vm/services/heapDumper.cpp	Fri Nov 09 16:45:20 2012 -0800
@@ -1117,8 +1117,8 @@
   writer->write_symbolID(m->name());                // method's name
   writer->write_symbolID(m->signature());           // method's signature
 
-  assert(Klass::cast(m->method_holder())->oop_is_instance(), "not InstanceKlass");
-  writer->write_symbolID(InstanceKlass::cast(m->method_holder())->source_file_name());  // source file name
+  assert(m->method_holder()->oop_is_instance(), "not InstanceKlass");
+  writer->write_symbolID(m->method_holder()->source_file_name());  // source file name
   writer->write_u4(class_serial_num);               // class serial number
   writer->write_u4((u4) line_number);               // line number
 }