Nomenclature improvements.

Change-Id: I809ab04b6ee74bb8141791e1f3f5d7e3f4efb61c
diff --git a/src/check_jni.cc b/src/check_jni.cc
index c724eb2..3b7c748 100644
--- a/src/check_jni.cc
+++ b/src/check_jni.cc
@@ -122,15 +122,15 @@
   // such as NewByteArray.
   // If -verbose:third-party-jni is on, we want to log any JNI function calls
   // made by a third-party native method.
-  std::string className(MethodHelper(method).GetDeclaringClassDescriptor());
-  if (!vm->trace.empty() && className.find(vm->trace) != std::string::npos) {
+  std::string class_name(MethodHelper(method).GetDeclaringClassDescriptor());
+  if (!vm->trace.empty() && class_name.find(vm->trace) != std::string::npos) {
     return true;
   }
   if (VLOG_IS_ON(third_party_jni)) {
     // Return true if we're trying to log all third-party JNI activity and 'method' doesn't look
     // like part of Android.
     for (size_t i = 0; gBuiltInPrefixes[i] != NULL; ++i) {
-      if (StartsWith(className, gBuiltInPrefixes[i])) {
+      if (StartsWith(class_name, gBuiltInPrefixes[i])) {
         return false;
       }
     }
@@ -148,30 +148,21 @@
   }
 
   // For JavaVM* functions.
-  explicit ScopedCheck(JavaVM* vm, bool hasMethod, const char* functionName) {
-    Init(NULL, vm, kFlag_Invocation, functionName, hasMethod);
+  explicit ScopedCheck(JavaVM* vm, bool has_method, const char* functionName) {
+    Init(NULL, vm, kFlag_Invocation, functionName, has_method);
   }
 
   bool ForceCopy() {
     return Runtime::Current()->GetJavaVM()->force_copy;
   }
 
-  /*
-   * In some circumstances the VM will screen class names, but it doesn't
-   * for class lookup.  When things get bounced through a class loader, they
-   * can actually get normalized a couple of times; as a result, passing in
-   * a class name like "java.lang.Thread" instead of "java/lang/Thread" will
-   * work in some circumstances.
-   *
-   * This is incorrect and could cause strange behavior or compatibility
-   * problems, so we want to screen that out here.
-   *
-   * We expect "fully-qualified" class names, like "java/lang/Thread" or
-   * "[Ljava/lang/Object;".
-   */
-  void CheckClassName(const char* className) {
-    if (!IsValidJniClassName(className)) {
-      LOG(ERROR) << "JNI ERROR: illegal class name '" << className << "' (" << function_name_ << ")\n"
+  // Checks that 'class_name' is a valid "fully-qualified" JNI class name, like "java/lang/Thread"
+  // or "[Ljava/lang/Object;". A ClassLoader can actually normalize class names a couple of
+  // times, so using "java.lang.Thread" instead of "java/lang/Thread" might work in some
+  // circumstances, but this is incorrect.
+  void CheckClassName(const char* class_name) {
+    if (!IsValidJniClassName(class_name)) {
+      LOG(ERROR) << "JNI ERROR: illegal class name '" << class_name << "' (" << function_name_ << ")\n"
                  << "           (should be of the form 'java/lang/String', [Ljava/lang/String;' or '[[B')\n";
       JniAbort();
     }
@@ -653,16 +644,15 @@
   }
 
  private:
-  void Init(JNIEnv* env, JavaVM* vm, int flags, const char* functionName, bool hasMethod) {
+  // Set "has_method" to true if we have a valid thread with a method pointer.
+  // We won't have one before attaching a thread, after detaching a thread, or
+  // when shutting down the runtime.
+  void Init(JNIEnv* env, JavaVM* vm, int flags, const char* functionName, bool has_method) {
     env_ = reinterpret_cast<JNIEnvExt*>(env);
     vm_ = reinterpret_cast<JavaVMExt*>(vm);
     flags_ = flags;
     function_name_ = functionName;
-
-    // Set "hasMethod" to true if we have a valid thread with a method pointer.
-    // We won't have one before attaching a thread, after detaching a thread, or
-    // after destroying the VM.
-    has_method_ = hasMethod;
+    has_method_ = has_method;
   }
 
   /*
@@ -760,7 +750,7 @@
   void CheckThread(int flags) {
     Thread* self = Thread::Current();
     if (self == NULL) {
-      LOG(ERROR) << "JNI ERROR: non-VM thread making JNI calls";
+      LOG(ERROR) << "JNI ERROR: a thread is making JNI calls without being attached";
       JniAbort();
       return;
     }
@@ -1124,7 +1114,7 @@
 
 /*
  * Perform the array "release" operation, which may or may not copy data
- * back into the VM, and may or may not release the underlying storage.
+ * back into the managed heap, and may or may not release the underlying storage.
  */
 void ReleaseGuardedPACopy(JNIEnv* env, jarray java_array, void* dataBuf, int mode) {
   if (reinterpret_cast<uintptr_t>(dataBuf) == kNoCopyMagic) {
diff --git a/src/compiler/codegen/arm/ArmLIR.h b/src/compiler/codegen/arm/ArmLIR.h
index a43702c..2d3028a 100644
--- a/src/compiler/codegen/arm/ArmLIR.h
+++ b/src/compiler/codegen/arm/ArmLIR.h
@@ -171,7 +171,6 @@
 
 /*
  * Annotate special-purpose core registers:
- *   - VM: r6SELF
  *   - ARM architecture: r13sp, r14lr, and r15pc
  *
  * rPC, rFP, and rSELF are for architecture-independent code to use.
diff --git a/src/dalvik_system_VMDebug.cc b/src/dalvik_system_VMDebug.cc
index 557a421..76750d7 100644
--- a/src/dalvik_system_VMDebug.cc
+++ b/src/dalvik_system_VMDebug.cc
@@ -29,10 +29,6 @@
 
 namespace art {
 
-/*
- * Return a set of strings describing available VM features (this is chiefly
- * of interest to DDMS).
- */
 static jobjectArray VMDebug_getVmFeatureList(JNIEnv* env, jclass) {
   std::vector<std::string> features;
   features.push_back("method-trace-profiling");
@@ -211,18 +207,10 @@
   LOG(INFO) << "---";
 }
 
-/*
- * Dump the current thread's interpreted stack and abort the VM.  Useful
- * for seeing both interpreted and native stack traces.
- */
 static void VMDebug_crash(JNIEnv*, jclass) {
-  LOG(FATAL) << "Crashing VM on request";
+  LOG(FATAL) << "Crashing runtime on request";
 }
 
-/*
- * Provide a hook for gdb to hang to so that the VM can be stopped when
- * user-tagged source locations are being executed.
- */
 static void VMDebug_infopoint(JNIEnv*, jclass, jint id) {
   LOG(INFO) << "VMDebug infopoint " << id << " hit";
 }
diff --git a/src/debugger.cc b/src/debugger.cc
index 78acf31..1f7b0de 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -433,11 +433,11 @@
 
 void Dbg::GcDidFinish() {
   if (gDdmHpifWhen != HPIF_WHEN_NEVER) {
-    LOG(DEBUG) << "Sending VM heap info to DDM";
+    LOG(DEBUG) << "Sending heap info to DDM";
     DdmSendHeapInfo(gDdmHpifWhen);
   }
   if (gDdmHpsgWhen != HPSG_WHEN_NEVER) {
-    LOG(DEBUG) << "Dumping VM heap to DDM";
+    LOG(DEBUG) << "Dumping heap to DDM";
     DdmSendHeapSegments(false);
   }
   if (gDdmNhsgWhen != HPSG_WHEN_NEVER) {
@@ -2167,7 +2167,7 @@
   {
     /*
      * We change our (JDWP thread) status, which should be THREAD_RUNNING,
-     * so the VM can suspend for a GC if the invoke request causes us to
+     * so we can suspend for a GC if the invoke request causes us to
      * run out of memory.  It's also a good idea to change it before locking
      * the invokeReq mutex, although that should never be held for long.
      */
@@ -2225,7 +2225,7 @@
 void Dbg::ExecuteMethod(DebugInvokeReq* pReq) {
   Thread* self = Thread::Current();
 
-  // We can be called while an exception is pending in the VM.  We need
+  // We can be called while an exception is pending. We need
   // to preserve that across the method invocation.
   SirtRef<Throwable> old_exception(self->GetException());
   self->ClearException();
@@ -2358,7 +2358,7 @@
    *
    * We could avoid this by returning type/data/offset/length and having
    * the caller be aware of the object lifetime issues, but that
-   * integrates the JDWP code more tightly into the VM, and doesn't work
+   * integrates the JDWP code more tightly into the rest of the runtime, and doesn't work
    * if we have responses for multiple chunks.
    *
    * So we're pretty much stuck with copying data around multiple times.
diff --git a/src/debugger.h b/src/debugger.h
index fac9705..77c307c 100644
--- a/src/debugger.h
+++ b/src/debugger.h
@@ -123,7 +123,6 @@
 
   static void UndoDebuggerSuspensions();
 
-  // The debugger wants the VM to exit.
   static void Exit(int status);
 
   static void VisitRoots(Heap::RootVisitor* visitor, void* arg);
diff --git a/src/dex_verifier.cc b/src/dex_verifier.cc
index 6fd7c20..aedd599 100644
--- a/src/dex_verifier.cc
+++ b/src/dex_verifier.cc
@@ -1489,8 +1489,8 @@
     Fail(VERIFY_ERROR_GENERIC) << "branch offset of zero not allowed at" << (void*) cur_offset;
     return false;
   }
-  // Check for 32-bit overflow. This isn't strictly necessary if we can depend on the VM to have
-  // identical "wrap-around" behavior, but it's unwise to depend on that.
+  // Check for 32-bit overflow. This isn't strictly necessary if we can depend on the runtime
+  // to have identical "wrap-around" behavior, but it's unwise to depend on that.
   if (((int64_t) cur_offset + (int64_t) offset) != (int64_t) (cur_offset + offset)) {
     Fail(VERIFY_ERROR_GENERIC) << "branch target overflow " << (void*) cur_offset << " +" << offset;
     return false;
diff --git a/src/heap.cc b/src/heap.cc
index b12ff2d..d847682 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -482,11 +482,9 @@
     return ptr;
   }
 
-  // Most allocations should have succeeded by now, so the heap is
-  // really full, really fragmented, or the requested size is really
-  // big.  Do another GC, collecting SoftReferences this time.  The VM
-  // spec requires that all SoftReferences have been collected and
-  // cleared before throwing an OOME.
+  // Most allocations should have succeeded by now, so the heap is really full, really fragmented,
+  // or the requested size is really big. Do another GC, collecting SoftReferences this time. The
+  // VM spec requires that all SoftReferences have been collected and cleared before throwing OOME.
 
   // OLD-TODO: wait for the finalizers from the previous GC to finish
   VLOG(gc) << "Forcing collection of SoftReferences for " << PrettySize(alloc_size) << " allocation";
diff --git a/src/indirect_reference_table.h b/src/indirect_reference_table.h
index 72ff1c8..b1f6d8c 100644
--- a/src/indirect_reference_table.h
+++ b/src/indirect_reference_table.h
@@ -35,8 +35,8 @@
  * The table contains object references that are part of the GC root set.
  * When an object is added we return an IndirectRef that is not a valid
  * pointer but can be used to find the original value in O(1) time.
- * Conversions to and from indirect refs are performed on JNI method calls
- * in and out of the VM, so they need to be very fast.
+ * Conversions to and from indirect references are performed on upcalls
+ * and downcalls, so they need to be very fast.
  *
  * To be efficient for JNI local variable storage, we need to provide
  * operations that allow us to operate on segments of the table, where
@@ -156,8 +156,7 @@
  *
  * To get the desired behavior for JNI locals, we need to know the bottom
  * and top of the current "segment".  The top is managed internally, and
- * the bottom is passed in as a function argument (the VM keeps it in a
- * slot in the interpreted stack frame).  When we call a native method or
+ * the bottom is passed in as a function argument.  When we call a native method or
  * push a local frame, the current top index gets pushed on, and serves
  * as the new bottom.  When we pop a frame off, the value from the stack
  * becomes the new top index, and the value stored in the previous frame
@@ -169,12 +168,6 @@
  * Instead of a "bottom" argument we take a "cookie", which includes the
  * bottom index and the count of holes below the bottom.
  *
- * We need to minimize method call/return overhead.  If we store the
- * "cookie" externally, on the interpreted call stack, the VM can handle
- * pushes and pops with a single 4-byte load and store.  (We could also
- * store it internally in a public structure, but the local JNI refs are
- * logically tied to interpreted stack frames anyway.)
- *
  * Common alternative implementation: make IndirectRef a pointer to the
  * actual reference slot.  Instead of getting a table and doing a lookup,
  * the lookup can be done instantly.  Operations like determining the
diff --git a/src/jni_compiler.cc b/src/jni_compiler.cc
index 25d76ca..08d3109 100644
--- a/src/jni_compiler.cc
+++ b/src/jni_compiler.cc
@@ -45,7 +45,7 @@
   if (new_state == Thread::kRunnable) {
     /*
      * Change our status to Thread::kRunnable.  The transition requires
-     * that we check for pending suspension, because the VM considers
+     * that we check for pending suspension, because the runtime considers
      * us to be "asleep" in all other states, and another thread could
      * be performing a GC now.
      */
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 714ca96..dbee18b 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -841,22 +841,7 @@
   static jthrowable ExceptionOccurred(JNIEnv* env) {
     ScopedJniThreadState ts(env);
     Object* exception = ts.Self()->GetException();
-    if (exception == NULL) {
-      return NULL;
-    } else {
-      // TODO: if adding a local reference failing causes the VM to abort
-      // then the following check will never occur.
-      jthrowable localException = AddLocalReference<jthrowable>(env, exception);
-      if (localException == NULL) {
-        // We were unable to add a new local reference, and threw a new
-        // exception.  We can't return "exception", because it's not a
-        // local reference.  So we have to return NULL, indicating that
-        // there was no exception, even though it's pretty much raining
-        // exceptions in here.
-        LOG(WARNING) << "JNI WARNING: addLocal/exception combo";
-      }
-      return localException;
-    }
+    return (exception != NULL) ? AddLocalReference<jthrowable>(env, exception) : NULL;
   }
 
   static void FatalError(JNIEnv* env, const char* msg) {
diff --git a/src/monitor.cc b/src/monitor.cc
index 6a7b66f..cfc7d49 100644
--- a/src/monitor.cc
+++ b/src/monitor.cc
@@ -613,12 +613,9 @@
         Inflate(self, obj);
       }
     } else if (LW_LOCK_OWNER(thin) == 0) {
-      /*
-       * The lock is unowned.  Install the thread id of the
-       * calling thread into the owner field.  This is the
-       * common case.  In performance critical code the JIT
-       * will have tried this before calling out to the VM.
-       */
+      // The lock is unowned. Install the thread id of the calling thread into the owner field.
+      // This is the common case: compiled code will have tried this before calling back into
+      // the runtime.
       newThin = thin | (threadId << LW_LOCK_OWNER_SHIFT);
       if (android_atomic_acquire_cas(thin, newThin, thinp) != 0) {
         // The acquire failed. Try again.
@@ -626,8 +623,8 @@
       }
     } else {
       VLOG(monitor) << StringPrintf("monitor: thread %d spin on lock %p (a %s) owned by %d",
-          threadId, thinp, PrettyTypeOf(obj).c_str(), LW_LOCK_OWNER(thin));
-      // The lock is owned by another thread. Notify the VM that we are about to wait.
+                                    threadId, thinp, PrettyTypeOf(obj).c_str(), LW_LOCK_OWNER(thin));
+      // The lock is owned by another thread. Notify the runtime that we are about to wait.
       self->monitor_enter_object_ = obj;
       Thread::State oldStatus = self->SetState(Thread::kBlocked);
       // Spin until the thin lock is released or inflated.
@@ -663,7 +660,7 @@
             }
           }
         } else {
-          // The thin lock was inflated by another thread. Let the VM know we are no longer
+          // The thin lock was inflated by another thread. Let the runtime know we are no longer
           // waiting and try again.
           VLOG(monitor) << "monitor: thread " << threadId
                         << " found lock " << (void*) thinp << " surprise-fattened by another thread";
@@ -673,7 +670,7 @@
         }
       }
       VLOG(monitor) << StringPrintf("monitor: thread %d spin on lock %p done", threadId, thinp);
-      // We have acquired the thin lock. Let the VM know that we are no longer waiting.
+      // We have acquired the thin lock. Let the runtime know that we are no longer waiting.
       self->monitor_enter_object_ = NULL;
       self->SetState(oldStatus);
       // Fatten the lock.
diff --git a/src/oatexec.cc b/src/oatexec.cc
index 340c058..4f7228b 100644
--- a/src/oatexec.cc
+++ b/src/oatexec.cc
@@ -103,7 +103,7 @@
   return env->ExceptionCheck() ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
-// Parse arguments.  Most of it just gets passed through to the VM.
+// Parse arguments.  Most of it just gets passed through to the runtime.
 // The JNI spec defines a handful of standard arguments.
 int oatexec(int argc, char** argv) {
   setvbuf(stdout, NULL, _IONBF, 0);
@@ -115,7 +115,7 @@
   // If we're adding any additional stuff, e.g. function hook specifiers,
   // add them to the count here.
   //
-  // We're over-allocating, because this includes the options to the VM
+  // We're over-allocating, because this includes the options to the runtime
   // plus the options to the program.
   int option_count = argc;
   UniquePtr<JavaVMOption[]> options(new JavaVMOption[option_count]());
@@ -125,6 +125,7 @@
   //
   // [Do we need to catch & handle "-jar" here?]
   bool need_extra = false;
+  const char* what = NULL;
   int curr_opt, arg_idx;
   for (curr_opt = arg_idx = 0; arg_idx < argc; arg_idx++) {
     if (argv[arg_idx][0] != '-' && !need_extra) {
@@ -135,19 +136,17 @@
     // Some options require an additional argument.
     need_extra = false;
     if (strcmp(argv[arg_idx], "-classpath") == 0 || strcmp(argv[arg_idx], "-cp") == 0) {
-      // others?
       need_extra = true;
+      what = argv[arg_idx];
     }
   }
 
   if (need_extra) {
-    fprintf(stderr, "VM requires value after last option flag\n");
+    fprintf(stderr, "%s must be followed by an additional argument giving a value\n", what);
     return EXIT_FAILURE;
   }
 
-  // Make sure they provided a class name.  We do this after VM init
-  // so that things like "-Xrunjdwp:help" have the opportunity to emit
-  // a usage statement.
+  // Make sure they provided a class name.
   if (arg_idx == argc) {
     fprintf(stderr, "Class name required\n");
     return EXIT_FAILURE;
@@ -163,11 +162,11 @@
   init_args.nOptions = curr_opt;
   init_args.ignoreUnrecognized = JNI_FALSE;
 
-  // Start VM.  The current thread becomes the main thread of the VM.
+  // Start the runtime. The current thread becomes the main thread.
   JavaVM* vm = NULL;
   JNIEnv* env = NULL;
   if (JNI_CreateJavaVM(&vm, &env, &init_args) != JNI_OK) {
-    fprintf(stderr, "VM init failed (check log file)\n");
+    fprintf(stderr, "runtime failed to initialize (check log for details)\n");
     return EXIT_FAILURE;
   }
 
@@ -179,7 +178,7 @@
   }
 
   if (vm->DestroyJavaVM() != 0) {
-    fprintf(stderr, "Warning: VM did not shut down cleanly\n");
+    fprintf(stderr, "Warning: runtime did not shut down cleanly\n");
     rc = EXIT_FAILURE;
   }
 
diff --git a/src/object.cc b/src/object.cc
index 13e4732..f72dc28 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -1243,7 +1243,7 @@
   size_t component_shift = sizeof(size_t) * 8 - 1 - CLZ(component_size);
   if (data_size >> component_shift != size_t(component_count) || size < data_size) {
     Thread::Current()->ThrowNewExceptionF("Ljava/lang/OutOfMemoryError;",
-        "%s of length %d exceeds the VM limit",
+        "%s of length %d would overflow",
         PrettyDescriptor(array_class).c_str(), component_count);
     return NULL;
   }
diff --git a/src/object.h b/src/object.h
index fee4dd0..4e3e850 100644
--- a/src/object.h
+++ b/src/object.h
@@ -1805,8 +1805,8 @@
   // (for String[][][], this will be String[][]). NULL for non-array classes.
   Class* component_type_;
 
-  // DexCache of resolved constant pool entries
-  // (will be NULL for VM-generated, e.g. arrays and primitive classes)
+  // DexCache of resolved constant pool entries (will be NULL for classes generated by the
+  // runtime such as arrays and primitive classes).
   DexCache* dex_cache_;
 
   // static, private, and <init> methods
diff --git a/src/object_utils.h b/src/object_utils.h
index 631425e..d22098d 100644
--- a/src/object_utils.h
+++ b/src/object_utils.h
@@ -398,15 +398,15 @@
     } else {
       Runtime* runtime = Runtime::Current();
       if (method_ == runtime->GetResolutionMethod()) {
-        return "<VM internal resolution method>";
+        return "<runtime internal resolution method>";
       } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
-        return "<VM internal callee-save all registers method>";
+        return "<runtime internal callee-save all registers method>";
       } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
-        return "<VM internal callee-save reference registers method>";
+        return "<runtime internal callee-save reference registers method>";
       } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
-        return "<VM internal callee-save reference and argument registers method>";
+        return "<runtime internal callee-save reference and argument registers method>";
       } else {
-        return "<unknown VM internal method>";
+        return "<unknown runtime internal method>";
       }
     }
   }
diff --git a/src/runtime.cc b/src/runtime.cc
index 1378229..d07a6e5 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -166,7 +166,7 @@
   // thread, whether or not that was the thread that failed.  By
   // stuffing a value into a bogus address, we cause a segmentation
   // fault in the current thread, and get a useful log from debuggerd.
-  // We can also trivially tell the difference between a VM crash and
+  // We can also trivially tell the difference between a crash and
   // a deliberate abort by looking at the fault address.
   *reinterpret_cast<char*>(0xdeadd00d) = 38;
   abort();
diff --git a/src/thread.cc b/src/thread.cc
index ce81a8b..7faf8f5 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -697,7 +697,7 @@
   if (new_state == Thread::kRunnable) {
     /*
      * Change our status to Thread::kRunnable.  The transition requires
-     * that we check for pending suspension, because the VM considers
+     * that we check for pending suspension, because the runtime considers
      * us to be "asleep" in all other states, and another thread could
      * be performing a GC now.
      *
diff --git a/src/thread.h b/src/thread.h
index d764ff3..7bf9c41 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -80,7 +80,7 @@
     kInitializing = 5,        // allocated, not yet running --- TODO: unnecessary?
     kStarting     = 6,        // native thread started, not yet ready to run managed code
     kNative       = 7,        // off in a JNI native method
-    kVmWait       = 8,        // waiting on a VM resource
+    kVmWait       = 8,        // waiting on an internal runtime resource
     kSuspended    = 9,        // suspended, usually by GC or debugger
   };
 
@@ -567,7 +567,7 @@
   // JDWP invoke-during-breakpoint support.
   DebugInvokeReq* debug_invoke_req_;
 
-  // TLS key used to retrieve the VM thread object.
+  // TLS key used to retrieve the Thread*.
   static pthread_key_t pthread_key_self_;
 
   // Additional stack used by method tracer to store method and return pc values.