Reduce the scope of CheckJNI.

CheckJNI wasn't anonymous so that it could friend JniEnvExt. Add
accessors for the CheckJNI parts of JniEnvExt and make CheckJNI and
related classes anonymous. This is equivalent to making functions
within the scope of a file static and preferred now by cppstyle.
Make the force_copy_ field that could be const, const.
Test: m -j32; booted emulator.

Change-Id: I7e740d3b9bf4a3fedd30c4f44a852af67898d2f0
diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc
index 5549122..05f099f 100644
--- a/runtime/check_jni.cc
+++ b/runtime/check_jni.cc
@@ -46,6 +46,7 @@
 #include "well_known_classes.h"
 
 namespace art {
+namespace {
 
 using android::base::StringAppendF;
 using android::base::StringPrintf;
@@ -1211,7 +1212,7 @@
     // this particular instance of JNIEnv.
     if (env != threadEnv) {
       // Get the thread owning the JNIEnv that's being used.
-      Thread* envThread = reinterpret_cast<JNIEnvExt*>(env)->self_;
+      Thread* envThread = reinterpret_cast<JNIEnvExt*>(env)->GetSelf();
       AbortF("thread %s using JNIEnv* from thread %s",
              ToStr<Thread>(*self).c_str(), ToStr<Thread>(*envThread).c_str());
       return false;
@@ -1223,7 +1224,7 @@
     case kFlag_CritOkay:    // okay to call this method
       break;
     case kFlag_CritBad:     // not okay to call
-      if (threadEnv->critical_ > 0) {
+      if (threadEnv->GetCritical() > 0) {
         AbortF("thread %s using JNI after critical get",
                ToStr<Thread>(*self).c_str());
         return false;
@@ -1231,25 +1232,25 @@
       break;
     case kFlag_CritGet:     // this is a "get" call
       // Don't check here; we allow nested gets.
-      if (threadEnv->critical_ == 0) {
-        threadEnv->critical_start_us_ = self->GetCpuMicroTime();
+      if (threadEnv->GetCritical() == 0) {
+        threadEnv->SetCriticalStartUs(self->GetCpuMicroTime());
       }
-      threadEnv->critical_++;
+      threadEnv->SetCritical(threadEnv->GetCritical() + 1);
       break;
     case kFlag_CritRelease:  // this is a "release" call
-      if (threadEnv->critical_ == 0) {
+      if (threadEnv->GetCritical() == 0) {
         AbortF("thread %s called too many critical releases",
                ToStr<Thread>(*self).c_str());
         return false;
-      } else if (threadEnv->critical_ == 1) {
+      } else if (threadEnv->GetCritical() == 1) {
         // Leaving the critical region, possibly warn about long critical regions.
-        uint64_t critical_duration_us = self->GetCpuMicroTime() - threadEnv->critical_start_us_;
+        uint64_t critical_duration_us = self->GetCpuMicroTime() - threadEnv->GetCriticalStartUs();
         if (critical_duration_us > kCriticalWarnTimeUs) {
           LOG(WARNING) << "JNI critical lock held for "
                        << PrettyDuration(UsToNs(critical_duration_us)) << " on " << *self;
         }
       }
-      threadEnv->critical_--;
+      threadEnv->SetCritical(threadEnv->GetCritical() - 1);
       break;
     default:
       LOG(FATAL) << "Bad flags (internal error): " << flags_;
@@ -2621,7 +2622,7 @@
   }
 
   static const JNINativeInterface* baseEnv(JNIEnv* env) {
-    return reinterpret_cast<JNIEnvExt*>(env)->unchecked_functions_;
+    return reinterpret_cast<JNIEnvExt*>(env)->GetUncheckedFunctions();
   }
 
   static jobject NewRef(const char* function_name, JNIEnv* env, jobject obj, IndirectRefKind kind) {
@@ -3847,10 +3848,6 @@
   CheckJNI::GetObjectRefType,
 };
 
-const JNINativeInterface* GetCheckJniNativeInterface() {
-  return &gCheckNativeInterface;
-}
-
 class CheckJII {
  public:
   static jint DestroyJavaVM(JavaVM* vm) {
@@ -3922,6 +3919,12 @@
   CheckJII::AttachCurrentThreadAsDaemon
 };
 
+}  // anonymous namespace
+
+const JNINativeInterface* GetCheckJniNativeInterface() {
+  return &gCheckNativeInterface;
+}
+
 const JNIInvokeInterface* GetCheckJniInvokeInterface() {
   return &gCheckInvokeInterface;
 }
diff --git a/runtime/java_vm_ext.h b/runtime/java_vm_ext.h
index 8c81c25..ac20afe 100644
--- a/runtime/java_vm_ext.h
+++ b/runtime/java_vm_ext.h
@@ -225,7 +225,7 @@
 
   // Extra checking.
   bool check_jni_;
-  bool force_copy_;
+  const bool force_copy_;
   const bool tracing_enabled_;
 
   // Extra diagnostics.
diff --git a/runtime/jni_env_ext.h b/runtime/jni_env_ext.h
index 0e8fd03..291ac48 100644
--- a/runtime/jni_env_ext.h
+++ b/runtime/jni_env_ext.h
@@ -96,6 +96,15 @@
   }
 
   Thread* GetSelf() const { return self_; }
+  uint32_t GetCritical() const { return critical_; }
+  void SetCritical(uint32_t new_critical) { critical_ = new_critical; }
+  uint64_t GetCriticalStartUs() const { return critical_start_us_; }
+  void SetCriticalStartUs(uint64_t new_critical_start_us) {
+    critical_start_us_ = new_critical_start_us;
+  }
+  const JNINativeInterface* GetUncheckedFunctions() const {
+    return unchecked_functions_;
+  }
   JavaVMExt* GetVm() const { return vm_; }
 
   bool IsRuntimeDeleted() const { return runtime_deleted_; }
@@ -190,9 +199,7 @@
   // If we are a JNI env for a daemon thread with a deleted runtime.
   bool runtime_deleted_;
 
-  friend class CheckJNI;
   friend class JNI;
-  friend class ScopedCheck;
   friend class ScopedJniEnvLocalRefState;
   friend class Thread;
   ART_FRIEND_TEST(JniInternalTest, JNIEnvExtOffsets);