7022998: JSR 292 recursive method handle calls inline themselves infinitely
authortwisti
Mon, 28 Mar 2011 03:58:07 -0700
changeset 8872 36680c58660e
parent 8871 5c3b26c4119e
child 8873 d3031147b912
7022998: JSR 292 recursive method handle calls inline themselves infinitely Reviewed-by: never, kvn
hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp
hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
hotspot/src/share/vm/code/nmethod.cpp
hotspot/src/share/vm/code/nmethod.hpp
hotspot/src/share/vm/compiler/compileBroker.cpp
hotspot/src/share/vm/compiler/compileBroker.hpp
hotspot/src/share/vm/opto/bytecodeInfo.cpp
hotspot/src/share/vm/opto/doCall.cpp
hotspot/src/share/vm/opto/library_call.cpp
hotspot/src/share/vm/runtime/sharedRuntime.cpp
hotspot/src/share/vm/runtime/sharedRuntime.hpp
--- a/hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, 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
@@ -1769,6 +1769,7 @@
 // returns.
 nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
                                                 methodHandle method,
+                                                int compile_id,
                                                 int total_in_args,
                                                 int comp_args_on_stack, // in VMRegStackSlots
                                                 BasicType *in_sig_bt,
@@ -2462,6 +2463,7 @@
   __ flush();
 
   nmethod *nm = nmethod::new_native_nmethod(method,
+                                            compile_id,
                                             masm->code(),
                                             vep_offset,
                                             frame_complete,
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -1111,6 +1111,7 @@
 // returns.
 nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
                                                 methodHandle method,
+                                                int compile_id,
                                                 int total_in_args,
                                                 int comp_args_on_stack,
                                                 BasicType *in_sig_bt,
@@ -1854,6 +1855,7 @@
   __ flush();
 
   nmethod *nm = nmethod::new_native_nmethod(method,
+                                            compile_id,
                                             masm->code(),
                                             vep_offset,
                                             frame_complete,
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -1174,6 +1174,7 @@
 // returns.
 nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
                                                 methodHandle method,
+                                                int compile_id,
                                                 int total_in_args,
                                                 int comp_args_on_stack,
                                                 BasicType *in_sig_bt,
@@ -1881,6 +1882,7 @@
   __ flush();
 
   nmethod *nm = nmethod::new_native_nmethod(method,
+                                            compile_id,
                                             masm->code(),
                                             vep_offset,
                                             frame_complete,
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -30,6 +30,7 @@
 #include "c1/c1_InstructionPrinter.hpp"
 #include "ci/ciField.hpp"
 #include "ci/ciKlass.hpp"
+#include "compiler/compileBroker.hpp"
 #include "interpreter/bytecode.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "utilities/bitMap.inline.hpp"
@@ -3775,24 +3776,7 @@
 
 #ifndef PRODUCT
 void GraphBuilder::print_inline_result(ciMethod* callee, bool res) {
-  const char sync_char      = callee->is_synchronized()        ? 's' : ' ';
-  const char exception_char = callee->has_exception_handlers() ? '!' : ' ';
-  const char monitors_char  = callee->has_monitor_bytecodes()  ? 'm' : ' ';
-  tty->print("     %c%c%c ", sync_char, exception_char, monitors_char);
-  for (int i = 0; i < scope()->level(); i++) tty->print("  ");
-  if (res) {
-    tty->print("  ");
-  } else {
-    tty->print("- ");
-  }
-  tty->print("@ %d  ", bci());
-  callee->print_short_name();
-  tty->print(" (%d bytes)", callee->code_size());
-  if (_inline_bailout_msg) {
-    tty->print("  %s", _inline_bailout_msg);
-  }
-  tty->cr();
-
+  CompileTask::print_inlining(callee, scope()->level(), bci(), _inline_bailout_msg);
   if (res && CIPrintMethodCodes) {
     callee->print_codes();
   }
--- a/hotspot/src/share/vm/code/nmethod.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/code/nmethod.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -28,6 +28,7 @@
 #include "code/nmethod.hpp"
 #include "code/scopeDesc.hpp"
 #include "compiler/abstractCompiler.hpp"
+#include "compiler/compileBroker.hpp"
 #include "compiler/compileLog.hpp"
 #include "compiler/compilerOracle.hpp"
 #include "compiler/disassembler.hpp"
@@ -469,6 +470,7 @@
 
 
 nmethod* nmethod::new_native_nmethod(methodHandle method,
+  int compile_id,
   CodeBuffer *code_buffer,
   int vep_offset,
   int frame_complete,
@@ -485,7 +487,7 @@
     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
     nm = new (native_nmethod_size)
-      nmethod(method(), native_nmethod_size, &offsets,
+      nmethod(method(), native_nmethod_size, compile_id, &offsets,
               code_buffer, frame_size,
               basic_lock_owner_sp_offset, basic_lock_sp_offset,
               oop_maps);
@@ -610,6 +612,7 @@
 nmethod::nmethod(
   methodOop method,
   int nmethod_size,
+  int compile_id,
   CodeOffsets* offsets,
   CodeBuffer* code_buffer,
   int frame_size,
@@ -644,7 +647,7 @@
     _handler_table_offset    = _dependencies_offset;
     _nul_chk_table_offset    = _handler_table_offset;
     _nmethod_end_offset      = _nul_chk_table_offset;
-    _compile_id              = 0;  // default
+    _compile_id              = compile_id;
     _comp_level              = CompLevel_none;
     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
@@ -930,72 +933,11 @@
 #undef LOG_OFFSET
 
 
-void nmethod::print_compilation(outputStream *st, const char *method_name, const char *title,
-                                methodOop method, bool is_blocking, int compile_id, int bci, int comp_level) {
-  bool is_synchronized = false, has_xhandler = false, is_native = false;
-  int code_size = -1;
-  if (method != NULL) {
-    is_synchronized = method->is_synchronized();
-    has_xhandler    = method->has_exception_handler();
-    is_native       = method->is_native();
-    code_size       = method->code_size();
-  }
-  // print compilation number
-  st->print("%7d %3d", (int)tty->time_stamp().milliseconds(), compile_id);
-
-  // print method attributes
-  const bool is_osr = bci != InvocationEntryBci;
-  const char blocking_char  = is_blocking     ? 'b' : ' ';
-  const char compile_type   = is_osr          ? '%' : ' ';
-  const char sync_char      = is_synchronized ? 's' : ' ';
-  const char exception_char = has_xhandler    ? '!' : ' ';
-  const char native_char    = is_native       ? 'n' : ' ';
-  st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char);
-  if (TieredCompilation) {
-    st->print("%d ", comp_level);
-  }
-
-  // print optional title
-  bool do_nl = false;
-  if (title != NULL) {
-    int tlen = (int) strlen(title);
-    bool do_nl = false;
-    if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; }
-    st->print("%.*s", tlen, title);
-  } else {
-    do_nl = true;
-  }
-
-  // print method name string if given
-  if (method_name != NULL) {
-    st->print(method_name);
-  } else {
-    // otherwise as the method to print itself
-    if (method != NULL && !Universe::heap()->is_gc_active()) {
-      method->print_short_name(st);
-    } else {
-      st->print("(method)");
-    }
-  }
-
-  if (method != NULL) {
-    // print osr_bci if any
-    if (is_osr) st->print(" @ %d", bci);
-    // print method size
-    st->print(" (%d bytes)", code_size);
-  }
-  if (do_nl) st->cr();
-}
-
 // Print out more verbose output usually for a newly created nmethod.
-void nmethod::print_on(outputStream* st, const char* title) const {
+void nmethod::print_on(outputStream* st, const char* msg) const {
   if (st != NULL) {
     ttyLocker ttyl;
-    print_compilation(st, /*method_name*/NULL, title,
-                      method(), /*is_blocking*/false,
-                      compile_id(),
-                      is_osr_method() ? osr_entry_bci() : InvocationEntryBci,
-                      comp_level());
+    CompileTask::print_compilation(st, this, msg);
     if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this);
   }
 }
@@ -1309,8 +1251,7 @@
     }
   }
   if (PrintCompilation && _state != unloaded) {
-    print_on(tty, _state == zombie ? "made zombie " : "made not entrant ");
-    tty->cr();
+    print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
   }
 }
 
@@ -1816,7 +1757,7 @@
           break;
       }
       // Mark was clear when we first saw this guy.
-      NOT_PRODUCT(if (TraceScavenge)  print_on(tty, "oops_do, mark\n"));
+      NOT_PRODUCT(if (TraceScavenge)  print_on(tty, "oops_do, mark"));
       return false;
     }
   }
@@ -1841,7 +1782,7 @@
     nmethod* next = cur->_oops_do_mark_link;
     cur->_oops_do_mark_link = NULL;
     cur->fix_oop_relocations();
-    NOT_PRODUCT(if (TraceScavenge)  cur->print_on(tty, "oops_do, unmark\n"));
+    NOT_PRODUCT(if (TraceScavenge)  cur->print_on(tty, "oops_do, unmark"));
     cur = next;
   }
   void* required = _oops_do_mark_nmethods;
@@ -2396,7 +2337,7 @@
   ResourceMark rm;
   ttyLocker ttyl;   // keep the following output all in one block
 
-  tty->print("Compiled ");
+  tty->print("Compiled method ");
 
   if (is_compiled_by_c1()) {
     tty->print("(c1) ");
@@ -2408,8 +2349,8 @@
     tty->print("(nm) ");
   }
 
-  print_on(tty, "nmethod");
-  tty->cr();
+  print_on(tty, NULL);
+
   if (WizardMode) {
     tty->print("((nmethod*) "INTPTR_FORMAT ") ", this);
     tty->print(" for method " INTPTR_FORMAT , (address)method());
@@ -2796,7 +2737,8 @@
 #ifndef PRODUCT
 
 void nmethod::print_value_on(outputStream* st) const {
-  print_on(st, "nmethod");
+  st->print("nmethod");
+  print_on(st, NULL);
 }
 
 void nmethod::print_calls(outputStream* st) {
--- a/hotspot/src/share/vm/code/nmethod.hpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/code/nmethod.hpp	Mon Mar 28 03:58:07 2011 -0700
@@ -229,6 +229,7 @@
   // For native wrappers
   nmethod(methodOop method,
           int nmethod_size,
+          int compile_id,
           CodeOffsets* offsets,
           CodeBuffer *code_buffer,
           int frame_size,
@@ -299,6 +300,7 @@
                               int comp_level);
 
   static nmethod* new_native_nmethod(methodHandle method,
+                                     int compile_id,
                                      CodeBuffer *code_buffer,
                                      int vep_offset,
                                      int frame_complete,
@@ -500,8 +502,8 @@
   address continuation_for_implicit_exception(address pc);
 
   // On-stack replacement support
-  int   osr_entry_bci() const                     { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _entry_bci; }
-  address  osr_entry() const                      { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _osr_entry_point; }
+  int   osr_entry_bci() const                     { assert(is_osr_method(), "wrong kind of nmethod"); return _entry_bci; }
+  address  osr_entry() const                      { assert(is_osr_method(), "wrong kind of nmethod"); return _osr_entry_point; }
   void  invalidate_osr_method();
   nmethod* osr_link() const                       { return _osr_link; }
   void     set_osr_link(nmethod *n)               { _osr_link = n; }
@@ -608,10 +610,6 @@
   void verify_scopes();
   void verify_interrupt_point(address interrupt_point);
 
-  // print compilation helper
-  static void print_compilation(outputStream *st, const char *method_name, const char *title,
-                                methodOop method, bool is_blocking, int compile_id, int bci, int comp_level);
-
   // printing support
   void print()                          const;
   void print_code();
@@ -627,7 +625,7 @@
 
   // need to re-define this from CodeBlob else the overload hides it
   virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); }
-  void print_on(outputStream* st, const char* title) const;
+  void print_on(outputStream* st, const char* msg) const;
 
   // Logging
   void log_identity(xmlStream* log) const;
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -268,11 +268,6 @@
 }
 
 
-void CompileTask::print_compilation(outputStream *st, methodOop method, char* method_name) {
-  nmethod::print_compilation(st, method_name,/*title*/ NULL, method,
-                             is_blocking(), compile_id(), osr_bci(), comp_level());
-}
-
 // ------------------------------------------------------------------
 // CompileTask::print_line_on_error
 //
@@ -284,31 +279,115 @@
 // Otherwise it's the same as CompileTask::print_line()
 //
 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) {
-  methodOop method = (methodOop)JNIHandles::resolve(_method);
   // print compiler name
   st->print("%s:", CompileBroker::compiler(comp_level())->name());
-  char* method_name = NULL;
-  if (method != NULL) {
-    method_name = method->name_and_sig_as_C_string(buf, buflen);
-  }
-  print_compilation(st, method, method_name);
+  print_compilation(st);
 }
 
 // ------------------------------------------------------------------
 // CompileTask::print_line
 void CompileTask::print_line() {
-  Thread *thread = Thread::current();
-  methodHandle method(thread,
-                      (methodOop)JNIHandles::resolve(method_handle()));
-  ResourceMark rm(thread);
-
   ttyLocker ttyl;  // keep the following output all in one block
-
   // print compiler name if requested
   if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name());
-  print_compilation(tty, method(), NULL);
+  print_compilation();
+}
+
+
+// ------------------------------------------------------------------
+// CompileTask::print_compilation_impl
+void CompileTask::print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, bool is_osr_method, int osr_bci, bool is_blocking, const char* msg) {
+  st->print("%7d ", (int) st->time_stamp().milliseconds());  // print timestamp
+  st->print("%4d ", compile_id);    // print compilation number
+
+  // method attributes
+  const char compile_type   = is_osr_method                   ? '%' : ' ';
+  const char sync_char      = method->is_synchronized()       ? 's' : ' ';
+  const char exception_char = method->has_exception_handler() ? '!' : ' ';
+  const char blocking_char  = is_blocking                     ? 'b' : ' ';
+  const char native_char    = method->is_native()             ? 'n' : ' ';
+
+  // print method attributes
+  st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char);
+
+  if (TieredCompilation) {
+    if (comp_level != -1)  st->print("%d ", comp_level);
+    else                   st->print("- ");
+  }
+  st->print("     ");  // more indent
+
+  method->print_short_name(st);
+  if (is_osr_method) {
+    st->print(" @ %d", osr_bci);
+  }
+  st->print(" (%d bytes)", method->code_size());
+
+  if (msg != NULL) {
+    st->print("   %s", msg);
+  }
+  st->cr();
 }
 
+// ------------------------------------------------------------------
+// CompileTask::print_inlining
+void CompileTask::print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg) {
+  //         1234567
+  st->print("        ");     // print timestamp
+  //         1234
+  st->print("     ");        // print compilation number
+
+  // method attributes
+  const char sync_char      = method->is_synchronized()        ? 's' : ' ';
+  const char exception_char = method->has_exception_handlers() ? '!' : ' ';
+  const char monitors_char  = method->has_monitor_bytecodes()  ? 'm' : ' ';
+
+  // print method attributes
+  st->print(" %c%c%c  ", sync_char, exception_char, monitors_char);
+
+  if (TieredCompilation) {
+    st->print("  ");
+  }
+  st->print("     ");        // more indent
+  st->print("    ");         // initial inlining indent
+
+  for (int i = 0; i < inline_level; i++)  st->print("  ");
+
+  st->print("@ %d  ", bci);  // print bci
+  method->print_short_name(st);
+  st->print(" (%d bytes)", method->code_size());
+
+  if (msg != NULL) {
+    st->print("   %s", msg);
+  }
+  st->cr();
+}
+
+// ------------------------------------------------------------------
+// CompileTask::print_inline_indent
+void CompileTask::print_inline_indent(int inline_level, outputStream* st) {
+  //         1234567
+  st->print("        ");     // print timestamp
+  //         1234
+  st->print("     ");        // print compilation number
+  //         %s!bn
+  st->print("      ");       // print method attributes
+  if (TieredCompilation) {
+    st->print("  ");
+  }
+  st->print("     ");        // more indent
+  st->print("    ");         // initial inlining indent
+  for (int i = 0; i < inline_level; i++)  st->print("  ");
+}
+
+// ------------------------------------------------------------------
+// CompileTask::print_compilation
+void CompileTask::print_compilation(outputStream* st) {
+  oop rem = JNIHandles::resolve(method_handle());
+  assert(rem != NULL && rem->is_method(), "must be");
+  methodOop method = (methodOop) rem;
+  bool is_osr_method = osr_bci() != InvocationEntryBci;
+  print_compilation_impl(st, method, compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking());
+}
 
 // ------------------------------------------------------------------
 // CompileTask::log_task
@@ -1086,7 +1165,13 @@
   // do the compilation
   if (method->is_native()) {
     if (!PreferInterpreterNativeStubs) {
-      (void) AdapterHandlerLibrary::create_native_wrapper(method);
+      // Acquire our lock.
+      int compile_id;
+      {
+        MutexLocker locker(MethodCompileQueue_lock, THREAD);
+        compile_id = assign_compile_id(method, standard_entry_bci);
+      }
+      (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id);
     } else {
       return NULL;
     }
@@ -1194,7 +1279,6 @@
   assert(MethodCompileQueue_lock->owner() == Thread::current(),
          "must hold the compilation queue lock");
   bool is_osr = (osr_bci != standard_entry_bci);
-  assert(!method->is_native(), "no longer compile natives");
   uint id;
   if (CICountOSR && is_osr) {
     id = ++_osr_compilation_id;
--- a/hotspot/src/share/vm/compiler/compileBroker.hpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/compiler/compileBroker.hpp	Mon Mar 28 03:58:07 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, 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
@@ -56,7 +56,6 @@
   int          _hot_count;    // information about its invocation counter
   const char*  _comment;      // more info about the task
 
-  void print_compilation(outputStream *st, methodOop method, char* method_name);
  public:
   CompileTask() {
     _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
@@ -96,10 +95,26 @@
   CompileTask* prev() const                      { return _prev; }
   void         set_prev(CompileTask* prev)       { _prev = prev; }
 
+private:
+  static void  print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false, const char* msg = NULL);
+
+public:
+  void         print_compilation(outputStream* st = tty);
+  static void  print_compilation(outputStream* st, const nmethod* nm, const char* msg = NULL) {
+    print_compilation_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);
+  }
+
+  static void  print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL);
+  static void  print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
+    print_inlining(tty, method, inline_level, bci, msg);
+  }
+
+  static void  print_inline_indent(int inline_level, outputStream* st = tty);
+
   void         print();
   void         print_line();
+  void         print_line_on_error(outputStream* st, char* buf, int buflen);
 
-  void         print_line_on_error(outputStream* st, char* buf, int buflen);
   void         log_task(xmlStream* log);
   void         log_task_queued();
   void         log_task_start(CompileLog* log);
--- a/hotspot/src/share/vm/opto/bytecodeInfo.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/opto/bytecodeInfo.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
+#include "compiler/compileBroker.hpp"
 #include "compiler/compileLog.hpp"
 #include "interpreter/linkResolver.hpp"
 #include "oops/objArrayKlass.hpp"
@@ -75,13 +76,6 @@
   assert(!UseOldInlining, "do not use for old stuff");
 }
 
-
-
-static void print_indent(int depth) {
-  tty->print("      ");
-  for (int i = depth; i != 0; --i) tty->print("  ");
-}
-
 static bool is_init_with_ea(ciMethod* callee_method,
                             ciMethod* caller_method, Compile* C) {
   // True when EA is ON and a java constructor is called or
@@ -100,7 +94,7 @@
   if(callee_method->should_inline()) {
     *wci_result = *(WarmCallInfo::always_hot());
     if (PrintInlining && Verbose) {
-      print_indent(inline_depth());
+      CompileTask::print_inline_indent(inline_depth());
       tty->print_cr("Inlined method is hot: ");
     }
     return NULL;
@@ -116,7 +110,7 @@
      size < InlineThrowMaxSize ) {
     wci_result->set_profit(wci_result->profit() * 100);
     if (PrintInlining && Verbose) {
-      print_indent(inline_depth());
+      CompileTask::print_inline_indent(inline_depth());
       tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count());
     }
     return NULL;
@@ -138,9 +132,9 @@
 
     max_size = C->freq_inline_size();
     if (size <= max_size && TraceFrequencyInlining) {
-      print_indent(inline_depth());
+      CompileTask::print_inline_indent(inline_depth());
       tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count);
-      print_indent(inline_depth());
+      CompileTask::print_inline_indent(inline_depth());
       callee_method->print();
       tty->cr();
     }
@@ -315,8 +309,25 @@
   if( inline_depth() > MaxInlineLevel ) {
     return "inlining too deep";
   }
-  if( method() == callee_method &&
-      inline_depth() > MaxRecursiveInlineLevel ) {
+
+  // We need to detect recursive inlining of method handle targets: if
+  // the current method is a method handle adapter and one of the
+  // callers is the same method as the callee, we bail out if
+  // MaxRecursiveInlineLevel is hit.
+  if (method()->is_method_handle_adapter()) {
+    JVMState* jvms = caller_jvms();
+    int inline_level = 0;
+    while (jvms != NULL && jvms->has_method()) {
+      if (jvms->method() == callee_method) {
+        inline_level++;
+        if (inline_level > MaxRecursiveInlineLevel)
+          return "recursively inlining too deep";
+      }
+      jvms = jvms->caller();
+    }
+  }
+
+  if (method() == callee_method && inline_depth() > MaxRecursiveInlineLevel) {
     return "recursively inlining too deep";
   }
 
@@ -368,18 +379,14 @@
 #ifndef PRODUCT
 //------------------------------print_inlining---------------------------------
 // Really, the failure_msg can be a success message also.
-void InlineTree::print_inlining(ciMethod *callee_method, int caller_bci, const char *failure_msg) const {
-  print_indent(inline_depth());
-  tty->print("@ %d  ", caller_bci);
-  if( callee_method ) callee_method->print_short_name();
-  else                tty->print(" callee not monotonic or profiled");
-  tty->print("  %s", (failure_msg ? failure_msg : "inline"));
-  if( Verbose && callee_method ) {
+void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci, const char* failure_msg) const {
+  CompileTask::print_inlining(callee_method, inline_depth(), caller_bci, failure_msg ? failure_msg : "inline");
+  if (callee_method == NULL)  tty->print(" callee not monotonic or profiled");
+  if (Verbose && callee_method) {
     const InlineTree *top = this;
     while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
     tty->print("  bcs: %d+%d  invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
   }
-  tty->cr();
 }
 #endif
 
--- a/hotspot/src/share/vm/opto/doCall.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/opto/doCall.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, 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
@@ -27,6 +27,7 @@
 #include "ci/ciCallSite.hpp"
 #include "ci/ciMethodHandle.hpp"
 #include "classfile/vmSymbols.hpp"
+#include "compiler/compileBroker.hpp"
 #include "compiler/compileLog.hpp"
 #include "interpreter/linkResolver.hpp"
 #include "opto/addnode.hpp"
@@ -43,17 +44,17 @@
 #ifndef PRODUCT
 void trace_type_profile(ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) {
   if (TraceTypeProfile || PrintInlining || PrintOptoInlining) {
-    tty->print("   ");
-    for( int i = 0; i < depth; i++ ) tty->print("  ");
-    if (!PrintOpto) {
-      method->print_short_name();
-      tty->print(" ->");
+    if (!PrintInlining) {
+      if (!PrintOpto && !PrintCompilation) {
+        method->print_short_name();
+        tty->cr();
+      }
+      CompileTask::print_inlining(prof_method, depth, bci);
     }
-    tty->print(" @ %d  ", bci);
-    prof_method->print_short_name();
-    tty->print("  >>TypeProfile (%d/%d counts) = ", receiver_count, site_count);
+    CompileTask::print_inline_indent(depth);
+    tty->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count);
     prof_klass->name()->print_symbol();
-    tty->print_cr(" (%d bytes)", prof_method->code_size());
+    tty->cr();
   }
 }
 #endif
@@ -269,13 +270,13 @@
           }
           if (miss_cg != NULL) {
             if (next_hit_cg != NULL) {
-              NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)));
+              NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)));
               // We don't need to record dependency on a receiver here and below.
               // Whenever we inline, the dependency is added by Parse::Parse().
               miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX);
             }
             if (miss_cg != NULL) {
-              NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count));
+              NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count));
               cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0));
               if (cg != NULL)  return cg;
             }
--- a/hotspot/src/share/vm/opto/library_call.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
+#include "compiler/compileBroker.hpp"
 #include "compiler/compileLog.hpp"
 #include "oops/objArrayKlass.hpp"
 #include "opto/addnode.hpp"
@@ -388,11 +389,7 @@
 #endif
   if (kit.try_to_inline()) {
     if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) {
-      tty->print("Inlining intrinsic %s%s at bci:%d in",
-                 vmIntrinsics::name_at(intrinsic_id()),
-                 (is_virtual() ? " (virtual)" : ""), kit.bci());
-      kit.caller()->print_short_name(tty);
-      tty->print_cr(" (%d bytes)", kit.caller()->code_size());
+      CompileTask::print_inlining(kit.callee(), jvms->depth() - 1, kit.bci(), is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
     }
     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
     if (C->log()) {
--- a/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Mon Mar 28 03:58:07 2011 -0700
@@ -2479,20 +2479,10 @@
 // java compiled calling convention to the native convention, handlizes
 // arguments, and transitions to native.  On return from the native we transition
 // back to java blocking if a safepoint is in progress.
-nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method) {
+nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int compile_id) {
   ResourceMark rm;
   nmethod* nm = NULL;
 
-  if (PrintCompilation) {
-    ttyLocker ttyl;
-    tty->print("---   n%s ", (method->is_synchronized() ? "s" : " "));
-    method->print_short_name(tty);
-    if (method->is_static()) {
-      tty->print(" (static)");
-    }
-    tty->cr();
-  }
-
   assert(method->has_native_function(), "must have something valid to call!");
 
   {
@@ -2537,6 +2527,7 @@
       // Generate the compiled-to-native wrapper code
       nm = SharedRuntime::generate_native_wrapper(&_masm,
                                                   method,
+                                                  compile_id,
                                                   total_args_passed,
                                                   comp_args_on_stack,
                                                   sig_bt,regs,
@@ -2548,6 +2539,10 @@
 
   // Install the generated code.
   if (nm != NULL) {
+    if (PrintCompilation) {
+      ttyLocker ttyl;
+      CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : "");
+    }
     method->set_code(method, nm);
     nm->post_compiled_method_load_event();
   } else {
--- a/hotspot/src/share/vm/runtime/sharedRuntime.hpp	Sun Mar 27 13:17:37 2011 -0700
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.hpp	Mon Mar 28 03:58:07 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, 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
@@ -438,6 +438,7 @@
   // returns.
   static nmethod *generate_native_wrapper(MacroAssembler* masm,
                                           methodHandle method,
+                                          int compile_id,
                                           int total_args_passed,
                                           int max_arg,
                                           BasicType *sig_bt,
@@ -659,7 +660,7 @@
 
   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
                                         address i2c_entry, address c2i_entry, address c2i_unverified_entry);
-  static nmethod* create_native_wrapper(methodHandle method);
+  static nmethod* create_native_wrapper(methodHandle method, int compile_id);
   static AdapterHandlerEntry* get_adapter(methodHandle method);
 
 #ifdef HAVE_DTRACE_H