changeset 3652:aac12c75f805

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 16 Nov 2011 23:35:10 +0100
parents a31028282e3e (diff) 441d68905702 (current diff)
children 6aef50c6d967
files
diffstat 20 files changed, 217 insertions(+), 300 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/c1/c1_IR.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/c1/c1_IR.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -237,7 +237,7 @@
     // reexecute allowed only for the topmost frame
     bool reexecute = topmost ? should_reexecute() : false;
     bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.
-    recorder->describe_scope(pc_offset, scope()->method(), bci(), reexecute, false, is_method_handle_invoke, return_oop, locvals, expvals, monvals);
+    recorder->describe_scope(pc_offset, (methodOop)scope()->method()->get_oop(), bci(), reexecute, false, is_method_handle_invoke, return_oop, locvals, expvals, monvals);
   }
 };
 
--- a/src/share/vm/c1/c1_LIRAssembler.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/c1/c1_LIRAssembler.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -405,7 +405,7 @@
     if (s == NULL)  break;
     IRScope* scope = s->scope();
     //Always pass false for reexecute since these ScopeDescs are never used for deopt
-    debug_info->describe_scope(pc_offset, scope->method(), s->bci(), false/*reexecute*/, false/*rethrow_exception*/);
+    debug_info->describe_scope(pc_offset, (methodOop)scope->method()->get_oop(), s->bci(), false/*reexecute*/, false/*rethrow_exception*/);
   }
 
   debug_info->end_non_safepoint(pc_offset);
--- a/src/share/vm/ci/ciObjectFactory.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/ci/ciObjectFactory.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -230,7 +230,9 @@
   vmSymbols::SID sid = vmSymbols::find_sid(key);
   if (sid != vmSymbols::NO_SID) {
     // do not pollute the main cache with it
-    return vm_symbol_at(sid);
+    ciSymbol* result = vm_symbol_at(sid);
+    assert(result != NULL, "");
+    return result;
   }
 
   assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
--- a/src/share/vm/classfile/vmSymbols.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/classfile/vmSymbols.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -302,10 +302,11 @@
   template(com_sun_cri_ci_CiKind,                     "com/sun/cri/ci/CiKind")                                          \
   template(com_sun_cri_ci_CiRuntimeCall,              "com/sun/cri/ci/CiRuntimeCall")                                   \
   template(startCompiler_name,                        "startCompiler")                                                  \
+  template(bootstrap_name,                            "bootstrap")                                                      \
   template(shutdownCompiler_name,                     "shutdownCompiler")                                               \
   template(compileMethod_name,                        "compileMethod")                                                  \
   template(pollJavaQueue_name,                        "pollJavaQueue")                                                  \
-  template(compileMethod_signature,                   "(Lcom/oracle/max/graal/hotspot/HotSpotMethodResolved;I)V")       \
+  template(compileMethod_signature,                   "(Lcom/oracle/max/graal/hotspot/HotSpotMethodResolved;IZ)V")      \
   template(setOption_name,                            "setOption")                                                      \
   template(setDefaultOptions_name,                    "setDefaultOptions")                                              \
   template(setOption_signature,                       "(Ljava/lang/String;)Z")                                          \
@@ -453,6 +454,7 @@
   template(void_long_signature,                       "()J")                                      \
   template(void_float_signature,                      "()F")                                      \
   template(void_double_signature,                     "()D")                                      \
+  template(bool_void_signature,                       "(Z)V")                                     \
   template(int_void_signature,                        "(I)V")                                     \
   template(int_int_signature,                         "(I)I")                                     \
   template(char_char_signature,                       "(C)C")                                     \
--- a/src/share/vm/code/debugInfoRec.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/code/debugInfoRec.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -280,7 +280,7 @@
 // must call add_safepoint before: it sets PcDesc and this routine uses
 // the last PcDesc set
 void DebugInformationRecorder::describe_scope(int         pc_offset,
-                                              ciMethod*   method,
+                                              methodHandle   method,
                                               int         bci,
                                               bool        reexecute,
                                               bool        rethrow_exception,
@@ -307,7 +307,7 @@
   stream()->write_int(sender_stream_offset);
 
   // serialize scope
-  jobject method_enc = (method == NULL)? NULL: method->constant_encoding();
+  jobject method_enc = JNIHandles::make_local(Thread::current(), method());
   stream()->write_int(oop_recorder()->find_index(method_enc));
   stream()->write_bci(bci);
   assert(method == NULL ||
--- a/src/share/vm/code/debugInfoRec.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/code/debugInfoRec.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -98,7 +98,7 @@
   // by add_non_safepoint, and the locals, expressions, and monitors
   // must all be null.
   void describe_scope(int         pc_offset,
-                      ciMethod*   method,
+                      methodHandle   method,
                       int         bci,
                       bool        reexecute,
                       bool        rethrow_exception,
--- a/src/share/vm/compiler/compileBroker.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/compiler/compileBroker.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -591,8 +591,6 @@
     _last = task->prev();
   }
 
-  // (tw) Immediately set compiling flag.
-  JavaThread::current()->as_CompilerThread()->set_compiling(true);
   --_size;
 }
 
@@ -657,70 +655,6 @@
   }
 }
 
-// Bootstrap the graal compiler. Compiles all methods until compile queue is empty and no compilation is active.
-void CompileBroker::bootstrap_graal() {
-  HandleMark hm;
-  Thread* THREAD = Thread::current();
-  tty->print_cr("Bootstrapping graal....");
-
-  GraalCompiler* compiler = GraalCompiler::instance();
-  assert(compiler != NULL, "just checking");
-
-  jlong start = os::javaTimeMillis();
-  add_method_to_queue(SystemDictionary::Object_klass(), vmSymbols::object_initializer_name(), vmSymbols::void_method_signature());
-  add_method_to_queue(SystemDictionary::Object_klass(), vmSymbols::equals_name(), vmSymbols::object_boolean_signature());
-  add_method_to_queue(SystemDictionary::String_klass(), vmSymbols::length_name(), vmSymbols::void_int_signature());
-  add_method_to_queue(SystemDictionary::String_klass(), vmSymbols::object_initializer_name(), vmSymbols::void_method_signature());
-
-  int z = 0;
-  while (true) {
-    {
-      HandleMark hm;
-      ResourceMark rm;
-      MutexLocker locker(_c1_method_queue->lock(), Thread::current());
-      if (_c1_method_queue->is_empty()) {
-        MutexLocker mu(Threads_lock); // grab Threads_lock
-        JavaThread* current = Threads::first();
-        bool compiling = false;
-        while (current != NULL) {
-          if (current->is_Compiler_thread()) {
-            CompilerThread* comp_thread = current->as_CompilerThread();
-            if (comp_thread->is_compiling()) {
-              if (TraceGraal >= 4) {
-                tty->print_cr("Compile queue empty, but following thread is still compiling:");
-                comp_thread->print();
-              }
-              compiling = true;
-            }
-          }
-          current = current->next();
-        }
-        if (!compiling) {
-          break;
-        }
-      }
-      if (TraceGraal >= 5) {
-        _c1_method_queue->print();
-      }
-    }
-
-    {
-      //ThreadToNativeFromVM trans(JavaThread::current());
-      os::sleep(THREAD, 10, true);
-    }
-    ++z;
-  }
-
-  // Do a full garbage collection.
-  Universe::heap()->collect(GCCause::_java_lang_system_gc);
-
-  jlong diff = os::javaTimeMillis() - start;
-  tty->print_cr("Finished bootstrap in %d ms", diff);
-  if (CITime) CompileBroker::print_times();
-  tty->print_cr("===========================================================================");
-}
-
-
 void CompileBroker::notify_java_queue() {
   HandleMark hm;
   ResourceMark rm;
@@ -1111,7 +1045,7 @@
   {
     MutexLocker locker(queue->lock(), THREAD);
 
-    if (Thread::current()->is_Compiler_thread() && CompilerThread::current()->is_compiling() && !BackgroundCompilation) {
+    if (JavaThread::current()->is_compiling() && !BackgroundCompilation) {
 
       TRACE_graal_1("Recursive compile %s!", method->name_and_sig_as_C_string());
       method->set_not_compilable();
@@ -1182,16 +1116,23 @@
     // and in that case it's best to protect both the testing (here) of
     // these bits, and their updating (here and elsewhere) under a
     // common lock.
-    task = create_compile_task(queue,
+    /*task = create_compile_task(queue,
                                compile_id, method,
                                osr_bci, comp_level,
                                hot_method, hot_count, comment,
-                               blocking);
+                               blocking);*/
   }
 
-  if (blocking) {
+  if (!JavaThread::current()->is_compiling()) {
+    method->set_queued_for_compilation();
+    GraalCompiler::instance()->compile_method(method, osr_bci, blocking);
+  } else {
+    // Recursive compile request => ignore.
+  }
+
+  /*if (blocking) {
     wait_for_completion(task);
-  }
+  }*/
 }
 
 
@@ -1574,17 +1515,9 @@
     log->stamp();
     log->end_elem();
   }
-  
-  if (UseGraal) {
-    thread->set_compiling(true); // Prevent recursive compilations while the compiler is initializing.
-    ThreadToNativeFromVM trans(JavaThread::current());
-    GraalCompiler::instance()->initialize();
-  }
 
   while (true) {
     {
-      // Unset compiling flag.
-      thread->set_compiling(false);
 
       // We need this HandleMark to avoid leaking VM handles.
       HandleMark hm(thread);
@@ -1809,12 +1742,13 @@
 
     compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci);
 
-    if (!ci_env.failing() && task->code() == NULL) {
+    // TODO (tw): Check if this is OK.
+    /*if (!ci_env.failing() && task->code() == NULL) {
       //assert(false, "compiler should always document failure");
       // The compiler elected, without comment, not to register a result.
       // Do not attempt further compilations of this method.
       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
-    }
+    }*/
 
     if (ci_env.failing()) {
       // Copy this bit to the enclosing block:
--- a/src/share/vm/compiler/compileBroker.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/compiler/compileBroker.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -404,7 +404,6 @@
 
   static void print_compiler_threads_on(outputStream* st);
 
-  static void bootstrap_graal();
   static void add_method_to_queue(klassOop k, Symbol* name, Symbol* signature);
 
   static void notify_java_queue();
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -257,6 +257,7 @@
   ThreadToNativeFromVM t((JavaThread*) Thread::current());
   nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table,
     &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, false, install_code);
+  method->clear_queued_for_compilation();
 }
 
 // constructor used to create a stub
@@ -363,6 +364,7 @@
         } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) {
           assumption_ConcreteMethod(assumption);
         } else {
+          assumption->print();
           fatal("unexpected Assumption subclass");
         }
       }
@@ -474,7 +476,6 @@
 
   oop hotspot_method = CiCodePos::method(code_pos);
   methodOop method = getMethodFromHotSpotMethod(hotspot_method);
-  ciMethod *cimethod = (ciMethod *) _env->get_object(method);
   jint bci = CiCodePos::bci(code_pos);
   bool reexecute;
   if (bci == -1) {
@@ -546,9 +547,9 @@
       throw_exception = true;
     }
 
-    _debug_recorder->describe_scope(pc_offset, cimethod, bci, reexecute, throw_exception, false, false, locals_token, expressions_token, monitors_token);
+    _debug_recorder->describe_scope(pc_offset, method, bci, reexecute, throw_exception, false, false, locals_token, expressions_token, monitors_token);
   } else {
-    _debug_recorder->describe_scope(pc_offset, cimethod, bci, reexecute, false, false, false, NULL, NULL, NULL);
+    _debug_recorder->describe_scope(pc_offset, method, bci, reexecute, false, false, false, NULL, NULL, NULL);
   }
 }
 
--- a/src/share/vm/graal/graalCompiler.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalCompiler.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -41,9 +41,9 @@
 
 // Initialization
 void GraalCompiler::initialize() {
-  if (_initialized) return;
-  _initialized = true;
-  CompilerThread* THREAD = CompilerThread::current();
+  
+  ThreadToNativeFromVM trans(JavaThread::current());
+  JavaThread* THREAD = JavaThread::current();
   TRACE_graal_1("GraalCompiler::initialize");
 
   initialize_buffer_blob();
@@ -57,6 +57,8 @@
   }
   env->RegisterNatives(klass, VMEntries_methods, VMEntries_methods_count());
 
+  ResourceMark rm;
+  HandleMark hm;
   {
     VM_ENTRY_MARK;
     check_pending_exception("Could not register natives");
@@ -78,6 +80,12 @@
         vm_abort(false);
       }
     }
+    VMExits::startCompiler();
+  
+    _initialized = true;
+    if (BootstrapGraal) {
+      VMExits::bootstrap();
+    }
   }
 }
 
@@ -96,22 +104,28 @@
   }
 }
 
+void GraalCompiler::compile_method(methodHandle method, int entry_bci, jboolean blocking) {
+  EXCEPTION_CONTEXT
+  if (!_initialized) {
+    method->clear_queued_for_compilation();
+    method->invocation_counter()->reset();
+    method->backedge_counter()->reset();
+    return;
+  }
+  assert(_initialized, "must already be initialized");
+  ResourceMark rm;
+  ciEnv* current_env = JavaThread::current()->env();
+  JavaThread::current()->set_env(NULL);
+  JavaThread::current()->set_compiling(true);
+  Handle hotspot_method = GraalCompiler::createHotSpotMethodResolved(method, CHECK);
+  VMExits::compileMethod(hotspot_method, entry_bci, blocking);
+  JavaThread::current()->set_compiling(false);
+  JavaThread::current()->set_env(current_env);
+}
+
 // Compilation entry point for methods
 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
-  assert(_initialized, "must already be initialized");
-  VM_ENTRY_MARK;
-  ResourceMark rm;
-  HandleMark hm;
-
-  TRACE_graal_2("GraalCompiler::compile_method");
-
-  CompilerThread::current()->set_compiling(true);
-  methodOop method = (methodOop) target->get_oop();
-  Handle hotspot_method = GraalCompiler::createHotSpotMethodResolved(method, CHECK);
-  VMExits::compileMethod(hotspot_method, entry_bci);
-  CompilerThread::current()->set_compiling(false);
-
-  TRACE_graal_2("GraalCompiler::compile_method exit");
+  ShouldNotReachHere();
 }
 
 void GraalCompiler::exit() {
@@ -180,17 +194,9 @@
   return createHotSpotTypeResolved(klass, name, CHECK_NULL);
 }
 
-oop GraalCompiler::get_RiField(ciField *field, ciInstanceKlass* accessor_klass, Handle field_holder, Handle field_type, Bytecodes::Code byteCode, TRAPS) {
-  int offset;
-  if (byteCode != Bytecodes::_illegal) {
-    bool will_link = field->will_link_from_vm(accessor_klass, byteCode);
-    offset = (field->holder()->is_loaded() && will_link) ? field->offset() : -1;
-  } else {
-    offset = field->offset();
-  }
-  Handle field_name = VmIds::toString<Handle>(field->name()->get_symbol(), CHECK_0);
-  int flags = field->flags().as_int();
-  return VMExits::createRiField(field_holder, field_name, field_type, offset, flags, THREAD);
+oop GraalCompiler::get_RiField(int offset, int flags, Symbol* field_name, Handle field_holder, Handle field_type, Bytecodes::Code byteCode, TRAPS) {
+  Handle name = VmIds::toString<Handle>(field_name, CHECK_NULL);
+  return VMExits::createRiField(field_holder, name, field_type, offset, flags, CHECK_NULL);
 }
 
 oop GraalCompiler::createHotSpotTypeResolved(KlassHandle klass, Handle name, TRAPS) {
@@ -205,6 +211,7 @@
   HotSpotTypeResolved::set_compiler(obj, VMExits::compilerInstance()());
 
   if (klass->oop_is_instance()) {
+    ResourceMark rm;
     instanceKlass* ik = (instanceKlass*)klass()->klass_part();
     Handle full_name = java_lang_String::create_from_str(ik->signature_name(), CHECK_NULL);
     HotSpotType::set_name(obj, full_name());
--- a/src/share/vm/graal/graalCompiler.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalCompiler.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -54,6 +54,8 @@
   // Compilation entry point for methods
   virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci);
 
+  void compile_method(methodHandle target, int entry_bci, jboolean blocking);
+
   // Print compilation timers and statistics
   virtual void print_timers();
   
@@ -61,7 +63,7 @@
   static oop get_RiType(constantPoolHandle cp, int index, KlassHandle accessor, TRAPS);
   static oop get_RiType(Symbol* klass_name, TRAPS);
   static oop get_RiType(KlassHandle klass, TRAPS);
-  static oop get_RiField(ciField *field, ciInstanceKlass* accessor_klass, Handle field_holder, Handle field_type, Bytecodes::Code byteCode, TRAPS);
+  static oop get_RiField(int offset, int flags, Symbol* field_name, Handle field_holder, Handle field_type, Bytecodes::Code byteCode, TRAPS);
 
   static oop createHotSpotTypeResolved(KlassHandle klass, Handle name, TRAPS);
   static oop createHotSpotMethodResolved(methodHandle method, TRAPS);
--- a/src/share/vm/graal/graalEnv.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalEnv.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -152,6 +152,7 @@
 KlassHandle GraalEnv::get_klass_by_name(KlassHandle accessing_klass,
                                   Symbol* klass_name,
                                   bool require_local) {
+  ResourceMark rm;
   return get_klass_by_name_impl(accessing_klass,
                                                  constantPoolHandle(),
                                                  klass_name,
@@ -228,6 +229,7 @@
                                    int index,
                                    bool& is_accessible,
                                    KlassHandle accessor) {
+  ResourceMark rm;
   return get_klass_by_index_impl(cpool, index, is_accessible, accessor);
 }
 
@@ -286,6 +288,7 @@
 // Get a field by index from a klass's constant pool.
 void GraalEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd,
                                    int index) {
+  ResourceMark rm;
   return get_field_by_index_impl(accessor, fd, index);
 }
 
@@ -338,14 +341,13 @@
   int holder_index = cpool->klass_ref_index_at(index);
   bool holder_is_accessible;
   KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, KlassHandle(Thread::current(), accessor));
-  instanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder);
 
   // Get the method's name and signature.
   Symbol* name_sym = cpool->name_ref_at(index);
   Symbol* sig_sym  = cpool->signature_ref_at(index);
 
   if (holder_is_accessible) { // Our declared holder is loaded.
-    instanceKlass* lookup = declared_holder;
+    instanceKlass* lookup = get_instance_klass_for_declared_method_holder(holder);
     methodOop m = lookup_method(accessor, lookup, name_sym, sig_sym, bc);
     if (m != NULL &&
         (bc == Bytecodes::_invokestatic
@@ -393,6 +395,7 @@
 methodHandle GraalEnv::get_method_by_index(constantPoolHandle cpool,
                                      int index, Bytecodes::Code bc,
                                      instanceKlass* accessor) {
+  ResourceMark rm;
   assert(bc != Bytecodes::_invokedynamic, "invokedynamic not yet supported");
   return get_method_by_index_impl(cpool, index, bc, accessor);
 }
--- a/src/share/vm/graal/graalVMEntries.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalVMEntries.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -41,41 +41,7 @@
 }
 
 methodOop getMethodFromHotSpotMethod(oop hotspot_method) {
-  oop reflected = HotSpotMethodResolved::javaMirror(hotspot_method);
-  assert(reflected != NULL, "NULL not expected");
-  return (methodOop)reflected;
-
-  // (tw) Cannot use reflection code, because then the compiler can dead lock with the user application (test using -Xcomp).
-  /*
-  // method is a handle to a java.lang.reflect.Method object
-  oop mirror     = NULL;
-  int slot       = 0;
-
-  if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
-    mirror = java_lang_reflect_Constructor::clazz(reflected);
-    slot   = java_lang_reflect_Constructor::slot(reflected);
-  } else {
-    assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type");
-    mirror = java_lang_reflect_Method::clazz(reflected);
-    slot   = java_lang_reflect_Method::slot(reflected);
-  }
-  klassOop k     = java_lang_Class::as_klassOop(mirror);
-
-  // Make sure class is initialized before handing id's out to methods
-//  assert(instanceKlass::cast(k)->is_initialized(), "only initialized classes expected");
-  methodOop m = instanceKlass::cast(k)->method_with_idnum(slot);
-  assert(m != NULL, "deleted method?");
-  return m;*/
-}
-
-oop getReflectedMethod(methodOop method, TRAPS) {
-  assert(method != NULL, "NULL not expected");
-
-  if (!method->is_initializer() || method->is_static()) {
-    return Reflection::new_method(method, true, true, CHECK_NULL);
-  } else {
-    return Reflection::new_constructor(method, CHECK_NULL);
-  }
+  return (methodOop)HotSpotMethodResolved::javaMirror(hotspot_method);
 }
 
 // public byte[] RiMethod_code(HotSpotResolvedMethod method);
@@ -101,6 +67,7 @@
 JNIEXPORT jobjectArray JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1exceptionHandlers(JNIEnv *, jobject, jobject hotspot_method) {
   TRACE_graal_3("VMEntries::RiMethod_exceptionHandlers");
   VM_ENTRY_MARK
+  ResourceMark rm;
   methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
   typeArrayHandle handlers = method->exception_table();
   int handler_count = handlers.is_null() ? 0 : handlers->length() / 4;
@@ -214,23 +181,22 @@
 // public native int RiMethod_exceptionProbability(long vmId, int bci);
 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) {
   TRACE_graal_3("VMEntries::RiMethod_exceptionProbability");
-  {
-    VM_ENTRY_MARK;
-    methodOop method = getMethodFromHotSpotMethod(hotspot_method);
-    methodDataOop method_data = method->method_data();
-    if (method_data == NULL || !method_data->is_mature()) {
-      return -1;
-    }
-    ProfileData* data = method_data->bci_to_data(bci);
-    if (data == NULL) {
-      return 0;
-    }
-    uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0;
-    if (trap > 0) {
-      return 100;
-    } else {
-      return trap;
-    }
+  VM_ENTRY_MARK;
+  ResourceMark rm;
+  methodOop method = getMethodFromHotSpotMethod(hotspot_method);
+  methodDataOop method_data = method->method_data();
+  if (method_data == NULL || !method_data->is_mature()) {
+    return -1;
+  }
+  ProfileData* data = method_data->bci_to_data(bci);
+  if (data == NULL) {
+    return 0;
+  }
+  uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0;
+  if (trap > 0) {
+    return 100;
+  } else {
+    return trap;
   }
 }
 
@@ -266,13 +232,8 @@
   Handle obj;
   {
     VM_ENTRY_MARK;
+    ResourceMark rm;
     methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
-    if (strstr(method->name_and_sig_as_C_string(), "factor") != NULL) {
-//      tty->print_cr("here");
-    }
-    if (bci == 123) {
-//      tty->print_cr("here2");
-    }
     methodDataHandle method_data = method->method_data();
     if (method_data == NULL || !method_data->is_mature()) {
       return NULL;
@@ -329,27 +290,14 @@
 
 JNIEXPORT jdouble JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) {
   TRACE_graal_3("VMEntries::RiMethod_typeProfile");
-  ciMethodData* method_data;
-  ciMethod* cimethod;
-  {
-    VM_ENTRY_MARK;
-    assert(hotspot_method != NULL, "must not be null");
-    methodOop method = getMethodFromHotSpotMethod(hotspot_method);
-    assert(method != NULL, "method not found");
-    if (CURRENT_ENV == NULL) {
-      return -1;
-    }
-    assert(CURRENT_ENV != NULL, "current environment must be present");
-    cimethod = (ciMethod*)CURRENT_ENV->get_object(method);
-  }
-  assert(cimethod != NULL, "cimethod not found");
-  method_data = cimethod->method_data();
-
-  jfloat probability = -1;
+  ResourceMark rm;
+  methodOop method = getMethodFromHotSpotMethod(hotspot_method);
+  methodDataOop method_data = method->method_data();
 
   if (method_data == NULL || !method_data->is_mature()) return -1;
-
-  ciProfileData* data = method_data->bci_to_data(bci);
+  method_data->bci_to_data(bci);
+  
+  ProfileData* data = method_data->bci_to_data(bci);
   if (data == NULL || !data->is_JumpData())  return -1;
 
   // get taken and not taken values
@@ -375,20 +323,14 @@
 
 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2switchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) {
   TRACE_graal_3("VMEntries::RiMethod_typeProfile");
-  ciMethodData* method_data;
-  ciMethod* cimethod;
-  {
-    VM_ENTRY_MARK;
-    methodOop method = getMethodFromHotSpotMethod(hotspot_method);
-    cimethod = (ciMethod*)CURRENT_ENV->get_object(method);
-  }
-  method_data = cimethod->method_data();
-
-  jfloat probability = -1;
+  VM_ENTRY_MARK;
+  ResourceMark rm;
+  methodOop method = getMethodFromHotSpotMethod(hotspot_method);
+  methodDataOop method_data = method->method_data();
 
   if (method_data == NULL || !method_data->is_mature()) return NULL;
 
-  ciProfileData* data = method_data->bci_to_data(bci);
+  ProfileData* data = method_data->bci_to_data(bci);
   if (data == NULL || !data->is_MultiBranchData())  return NULL;
 
   MultiBranchData* branch_data = data->as_MultiBranchData();
@@ -410,14 +352,11 @@
   // We also check that individual counters are positive first, otherwise the sum can become positive.
   if (sum < 10 * (cases + 3)) return NULL;
 
-  {
-    VM_ENTRY_MARK;
-    typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL);
-    for (int i = 0; i < cases + 1; i++) {
-      probability->double_at_put(i, counts->at(i) / (double) sum);
-    }
-    return JNIHandles::make_local(probability);
+  typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL);
+  for (int i = 0; i < cases + 1; i++) {
+    probability->double_at_put(i, counts->at(i) / (double) sum);
   }
+  return JNIHandles::make_local(probability);
 }
 
 // public native boolean RiMethod_hasCompiledCode(HotSpotMethodResolved method);
@@ -431,6 +370,7 @@
 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) {
   TRACE_graal_3("VMEntries::RiSignature_lookupType");
   VM_ENTRY_MARK;
+  ResourceMark rm;
 
   Symbol* nameSymbol = VmIds::toSymbol(jname);
   Handle name = JNIHandles::resolve(jname);
@@ -530,10 +470,8 @@
   constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants();
 
   Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF);
-  ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder());
-  ciMethod *cimethod = CURRENT_ENV->get_method_by_index(cp, index, bc, loading_klass);
-  if (cimethod->is_loaded()) {
-    methodOop method = (methodOop) cimethod->get_oop();
+  methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, instanceKlass::cast(cp->pool_holder()));
+  if (!method.is_null()) {
     oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL);
     return JNIHandles::make_local(THREAD, ret);
   } else {
@@ -584,20 +522,24 @@
 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupField(JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte byteCode) {
   TRACE_graal_3("VMEntries::RiConstantPool_lookupField");
   VM_ENTRY_MARK;
+  ResourceMark rm;
 
   index = GraalCompiler::to_cp_index_u2(index);
   constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(constantPoolHolder)))->constants();
 
-  ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder());
-  ciField *field = CURRENT_ENV->get_field_by_index(loading_klass, index);
-  
   int nt_index = cp->name_and_type_ref_index_at(index);
   int sig_index = cp->signature_ref_index_at(nt_index);
   Symbol* signature = cp->symbol_at(sig_index);
+  int name_index = cp->name_ref_index_at(nt_index);
+  Symbol* name = cp->symbol_at(name_index);
   int holder_index = cp->klass_ref_index_at(index);
   Handle holder = GraalCompiler::get_RiType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
+  instanceKlassHandle holder_klass;
   
   Bytecodes::Code code = (Bytecodes::Code)(((int) byteCode) & 0xFF);
+  int offset = -1;
+  AccessFlags flags;
+  BasicType basic_type;
   if (holder->klass() == SystemDictionary::HotSpotTypeResolved_klass()) {
     FieldAccessInfo result;
     LinkResolver::resolve_field(result, cp, index,
@@ -606,61 +548,81 @@
     if (HAS_PENDING_EXCEPTION) {
       CLEAR_PENDING_EXCEPTION;
     }
-    //result.field_offset();
-    holder = GraalCompiler::get_RiType(result.klass(), CHECK_NULL);
+    offset = result.field_offset();
+    flags = result.access_flags();
+    holder_klass = result.klass()->as_klassOop();
+    basic_type = result.field_type();
+    holder = GraalCompiler::get_RiType(holder_klass, CHECK_NULL);
   }
-
+  
   Handle type = GraalCompiler::get_RiTypeFromSignature(cp, sig_index, cp->pool_holder(), CHECK_NULL);
-  Handle field_handle = GraalCompiler::get_RiField(field, loading_klass, holder, type, code, THREAD);
-  bool is_constant = field->is_constant();
-  if (is_constant && field->is_static()) {
-    ciConstant constant = field->constant_value();
-    oop constant_object = NULL;
-    switch (constant.basic_type()) {
-      case T_OBJECT:
-      case T_ARRAY:
-        {
-          ciObject* obj = constant.as_object();
-          if (obj->is_null_object()) {
-            constant_object = VMExits::createCiConstantObject(NULL, CHECK_0);
-          } else if (obj->can_be_constant()) {
-            constant_object = VMExits::createCiConstantObject(constant.as_object()->get_oop(), CHECK_0);
-          }
-        }
-        break;
-      case T_DOUBLE:
-        constant_object = VMExits::createCiConstantDouble(constant.as_double(), CHECK_0);
-        break;
-      case T_FLOAT:
-        constant_object = VMExits::createCiConstantFloat(constant.as_float(), CHECK_0);
-        break;
-      case T_LONG:
-        constant_object = VMExits::createCiConstant(CiKind::Long(), constant.as_long(), CHECK_0);
-        break;
-      case T_INT:
-        constant_object = VMExits::createCiConstant(CiKind::Int(), constant.as_int(), CHECK_0);
-        break;
-      case T_SHORT:
-        constant_object = VMExits::createCiConstant(CiKind::Short(), constant.as_int(), CHECK_0);
-        break;
-      case T_CHAR:
-        constant_object = VMExits::createCiConstant(CiKind::Char(), constant.as_int(), CHECK_0);
-        break;
-      case T_BYTE:
-        constant_object = VMExits::createCiConstant(CiKind::Byte(), constant.as_int(), CHECK_0);
-        break;
-      case T_BOOLEAN:
-        constant_object = VMExits::createCiConstant(CiKind::Boolean(), constant.as_int(), CHECK_0);
-        break;
-      default:
-        constant.print();
-        fatal("Unhandled constant");
-        break;
+  Handle field_handle = GraalCompiler::get_RiField(offset, flags.as_int(), name, holder, type, code, THREAD);
+
+  oop constant_object = NULL;
+    // Check to see if the field is constant.
+  if (!holder_klass.is_null() && holder_klass->is_initialized() && flags.is_final() && flags.is_static()) {
+    // This field just may be constant.  The only cases where it will
+    // not be constant are:
+    //
+    // 1. The field holds a non-perm-space oop.  The field is, strictly
+    //    speaking, constant but we cannot embed non-perm-space oops into
+    //    generated code.  For the time being we need to consider the
+    //    field to be not constant.
+    // 2. The field is a *special* static&final field whose value
+    //    may change.  The three examples are java.lang.System.in,
+    //    java.lang.System.out, and java.lang.System.err.
+
+    bool ok = true;
+    assert( SystemDictionary::System_klass() != NULL, "Check once per vm");
+    if( holder_klass->as_klassOop() == SystemDictionary::System_klass() ) {
+      // Check offsets for case 2: System.in, System.out, or System.err
+      if( offset == java_lang_System::in_offset_in_bytes()  ||
+          offset == java_lang_System::out_offset_in_bytes() ||
+          offset == java_lang_System::err_offset_in_bytes() ) {
+        ok = false;
+      }
     }
-    if (constant_object != NULL) {
-      HotSpotField::set_constant(field_handle, constant_object);
+
+    if (ok) {
+      Handle mirror = holder_klass->java_mirror();
+      switch(basic_type) {
+        case T_OBJECT:
+        case T_ARRAY:
+          constant_object = VMExits::createCiConstantObject(mirror->obj_field(offset), CHECK_0);
+          break;
+        case T_DOUBLE:
+          constant_object = VMExits::createCiConstantDouble(mirror->double_field(offset), CHECK_0);
+          break;
+        case T_FLOAT:
+          constant_object = VMExits::createCiConstantFloat(mirror->float_field(offset), CHECK_0);
+          break;
+        case T_LONG:
+          constant_object = VMExits::createCiConstant(CiKind::Long(), mirror->long_field(offset), CHECK_0);
+          break;
+        case T_INT:
+          constant_object = VMExits::createCiConstant(CiKind::Int(), mirror->int_field(offset), CHECK_0);
+          break;
+        case T_SHORT:
+          constant_object = VMExits::createCiConstant(CiKind::Short(), mirror->short_field(offset), CHECK_0);
+          break;
+        case T_CHAR:
+          constant_object = VMExits::createCiConstant(CiKind::Char(), mirror->char_field(offset), CHECK_0);
+          break;
+        case T_BYTE:
+          constant_object = VMExits::createCiConstant(CiKind::Byte(), mirror->byte_field(offset), CHECK_0);
+          break;
+        case T_BOOLEAN:
+          constant_object = VMExits::createCiConstant(CiKind::Boolean(), mirror->bool_field(offset), CHECK_0);
+          break;
+        default:
+          fatal("Unhandled constant");
+          break;
+      }
     }
   }
+  if (constant_object != NULL) {
+    HotSpotField::set_constant(field_handle, constant_object);
+  }
   return JNIHandles::make_local(THREAD, field_handle());
 }
 
@@ -770,6 +732,7 @@
 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1fields(JNIEnv *, jobject, jobject klass) {
   TRACE_graal_3("VMEntries::RiType_fields");
   VM_ENTRY_MARK;
+  ResourceMark rm;
 
   instanceKlassHandle k = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass));
   class MyFieldClosure : public FieldClosure {
--- a/src/share/vm/graal/graalVMEntries.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalVMEntries.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -28,8 +28,6 @@
 
 methodOop getMethodFromHotSpotMethod(oop hotspotMethod);
 
-oop getReflectedMethod(methodOop method, TRAPS);
-
 // nothing here - no need to define the jni method implementations in a header file
 
 
--- a/src/share/vm/graal/graalVMExits.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalVMExits.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -73,8 +73,6 @@
   JavaValue result(T_VOID);
   JavaCalls::call_static(&result, compilerImplKlass, vmSymbols::initialize_name(), vmSymbols::void_method_signature(), Thread::current());
   check_pending_exception("Couldn't initialize compiler");
-
-  startCompiler();
 }
 
 jboolean VMExits::setOption(Handle option) {
@@ -99,7 +97,7 @@
   check_pending_exception("Error while calling setDefaultOptions");
 }
 
-void VMExits::compileMethod(Handle hotspot_method, int entry_bci) {
+void VMExits::compileMethod(Handle hotspot_method, int entry_bci, jboolean blocking) {
   assert(!hotspot_method.is_null(), "just checking");
   Thread* THREAD = Thread::current();
   JavaValue result(T_VOID);
@@ -107,6 +105,7 @@
   args.push_oop(instance());
   args.push_oop(hotspot_method);
   args.push_int(entry_bci);
+  args.push_int(blocking);
   JavaCalls::call_interface(&result, vmExitsKlass(), vmSymbols::compileMethod_name(), vmSymbols::compileMethod_signature(), &args, THREAD);
   check_pending_exception("Error while calling compileMethod");
 }
@@ -140,6 +139,15 @@
   check_pending_exception("Error while calling startCompiler");
 }
 
+void VMExits::bootstrap() {
+  JavaThread* THREAD = JavaThread::current();
+  JavaValue result(T_VOID);
+  JavaCallArguments args;
+  args.push_oop(instance());
+  JavaCalls::call_interface(&result, vmExitsKlass(), vmSymbols::bootstrap_name(), vmSymbols::void_method_signature(), &args, THREAD);
+  check_pending_exception("Error while calling boostrap");
+}
+
 void VMExits::pollJavaQueue() {
   JavaThread* THREAD = JavaThread::current();
   JavaValue result(T_VOID);
--- a/src/share/vm/graal/graalVMExits.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/graal/graalVMExits.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -50,14 +50,17 @@
   // public static void HotSpotOptions.setDefaultOptions();
   static void setDefaultOptions();
 
-  // public abstract void compileMethod(long vmId, String name, int entry_bci);
-  static void compileMethod(Handle hotspot_method, int entry_bci);
+  // public abstract void compileMethod(long vmId, String name, int entry_bci, boolean blocking);
+  static void compileMethod(Handle hotspot_method, int entry_bci, jboolean blocking);
 
   // public abstract void shutdownCompiler();
   static void shutdownCompiler();
   
   // public abstract void startCompiler();
   static void startCompiler();
+  
+  // public abstract void bootstrap();
+  static void bootstrap();
 
   // public abstract void pollJavaQueue();
   static void pollJavaQueue();
--- a/src/share/vm/opto/output.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/opto/output.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -934,7 +934,7 @@
     assert(jvms->bci() >= InvocationEntryBci && jvms->bci() <= 0x10000, "must be a valid or entry BCI");
     assert(!jvms->should_reexecute() || depth == max_depth, "reexecute allowed only for the youngest");
     // Now we can describe the scope.
-    debug_info()->describe_scope(safepoint_pc_offset, scope_method, jvms->bci(), jvms->should_reexecute(), is_method_handle_invoke, return_oop, locvals, expvals, monvals);
+    debug_info()->describe_scope(safepoint_pc_offset, (methodOop)scope_method->get_oop(), jvms->bci(), jvms->should_reexecute(), is_method_handle_invoke, return_oop, locvals, expvals, monvals);
   } // End jvms loop
 
   // Mark the end of the scope set.
@@ -1017,7 +1017,7 @@
     JVMState* jvms = youngest_jvms->of_depth(depth);
     ciMethod* method = jvms->has_method() ? jvms->method() : NULL;
     assert(!jvms->should_reexecute() || depth==max_depth, "reexecute allowed only for the youngest");
-    debug_info->describe_scope(pc_offset, method, jvms->bci(), jvms->should_reexecute());
+    debug_info->describe_scope(pc_offset, (methodOop)method->get_oop(), jvms->bci(), jvms->should_reexecute());
   }
 
   // Mark the end of the scope set.
--- a/src/share/vm/prims/jni.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/prims/jni.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -3361,6 +3361,12 @@
     *vm = (JavaVM *)(&main_vm);
     *(JNIEnv**)penv = thread->jni_environment();
 
+    if (UseGraal) {
+      GraalCompiler* compiler = GraalCompiler::instance();
+      ciObjectFactory::initialize(); 
+      compiler->initialize();
+    }
+
     // Tracks the time application was running before GC
     RuntimeService::record_application_start();
 
@@ -3369,10 +3375,6 @@
        JvmtiExport::post_thread_start(thread);
     }
 
-    if (UseGraal && BootstrapGraal) {
-      CompileBroker::bootstrap_graal();
-    }
-
     // Check if we should compile all classes on bootclasspath
     NOT_PRODUCT(if (CompileTheWorld) ClassLoader::compile_the_world();)
     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
--- a/src/share/vm/runtime/thread.cpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/runtime/thread.cpp	Wed Nov 16 23:35:10 2011 +0100
@@ -2938,7 +2938,7 @@
 
 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
   assert(thread->is_Compiler_thread(), "must be compiler thread");
-  CompileBroker::compiler_thread_loop();
+  //CompileBroker::compiler_thread_loop();
 }
 
 // Create a CompilerThread
@@ -2948,7 +2948,6 @@
   _task  = NULL;
   _queue = queue;
   _counters = counters;
-  _is_compiling = false;
   _scanned_nmethod = NULL;
 
 #ifndef PRODUCT
--- a/src/share/vm/runtime/thread.hpp	Wed Nov 16 15:13:51 2011 +0100
+++ b/src/share/vm/runtime/thread.hpp	Wed Nov 16 23:35:10 2011 +0100
@@ -716,6 +716,7 @@
   // (tw) Necessary for holding a compilation buffer and ci environment. Moved from CompilerThread to JavaThread in order to enable code installation from Java application code.
   BufferBlob*   _buffer_blob;
   ciEnv*        _env;
+  bool          _is_compiling;
 
 #ifdef ASSERT
  private:
@@ -853,9 +854,6 @@
   volatile int     _exception_stack_size;        // Size of frame where exception happened
   volatile int     _is_method_handle_return;     // true (== 1) if the current exception PC is a MethodHandle call site.
 
-  // support for compilation
-  bool    _is_compiling;                         // is true if a compilation is active inthis thread (one compilation per thread possible)
-
   // support for JNI critical regions
   jint    _jni_active_critical;                  // count of entries into JNI critical region
 
@@ -916,6 +914,9 @@
     return (struct JNINativeInterface_ *)_jni_environment.functions;
   }
   
+  bool is_compiling() const                      { return _is_compiling; }
+  void set_compiling(bool b)                     { _is_compiling = b; }
+
   // Get/set the thread's compilation environment.
   ciEnv*        env()                            { return _env; }
   void          set_env(ciEnv* env)              { _env = env; }
@@ -942,10 +943,6 @@
   // Testers
   virtual bool is_Java_thread() const            { return true;  }
 
-  // compilation
-  void set_is_compiling(bool f)                  { _is_compiling = f; }
-  bool is_compiling() const                      { return _is_compiling; }
-
   // Thread chain operations
   JavaThread* next() const                       { return _next; }
   void set_next(JavaThread* p)                   { _next = p; }
@@ -1716,7 +1713,6 @@
   CompileLog*   _log;
   CompileTask*  _task;
   CompileQueue* _queue;
-  bool          _is_compiling;
 
   nmethod*      _scanned_nmethod;  // nmethod being scanned by the sweeper
 
@@ -1726,8 +1722,6 @@
 
   CompilerThread(CompileQueue* queue, CompilerCounters* counters);
 
-  bool is_compiling() const                      { return _is_compiling; }
-  void set_compiling(bool b)                     { _is_compiling = b; }
   bool is_Compiler_thread() const                { return true; }
   // Hide this compiler thread from external view.
   // (tw) For Graal, the compiler thread should be visible.