summaryrefslogtreecommitdiffstats
path: root/runtime/native/java_lang_ref_Reference.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2014-05-06 10:57:27 -0700
committerMathieu Chartier <mathieuc@google.com>2014-05-07 15:28:35 -0700
commit78f7b4c04ab6e8b5581921bc95b67a9beee1c246 (patch)
tree78b93c72007478b5bfc3b88ab413fa3d772da723 /runtime/native/java_lang_ref_Reference.cc
parent052a647973b590c9d5007a2e16f313f4e32a70bd (diff)
downloadandroid_art-78f7b4c04ab6e8b5581921bc95b67a9beee1c246.tar.gz
android_art-78f7b4c04ab6e8b5581921bc95b67a9beee1c246.tar.bz2
android_art-78f7b4c04ab6e8b5581921bc95b67a9beee1c246.zip
Add concurrent reference processing.
Concurrent reference processing currently works by going into native code from java.lang.ref.Reference.get(). From there, we have a fast path if the references aren't being processed which returns the referent without needing to access any locks. In the slow path we block until reference processing is complete. It may be possible to improve the slow path if the referent is blackened. TODO: Investigate doing the fast path in java code by using racy reads of a static volatile boolean. This will work as long as there are no suspend points inbetween the boolean read and referent read. Bug: 14381653 Change-Id: I1546b55be4691fe4ff4aa6d857b234cce7187d87
Diffstat (limited to 'runtime/native/java_lang_ref_Reference.cc')
-rw-r--r--runtime/native/java_lang_ref_Reference.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/runtime/native/java_lang_ref_Reference.cc b/runtime/native/java_lang_ref_Reference.cc
new file mode 100644
index 0000000000..f221ac60f5
--- /dev/null
+++ b/runtime/native/java_lang_ref_Reference.cc
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "gc/heap.h"
+#include "gc/reference_processor.h"
+#include "jni_internal.h"
+#include "mirror/object-inl.h"
+#include "mirror/reference-inl.h"
+#include "scoped_fast_native_object_access.h"
+
+namespace art {
+
+static jobject Reference_get(JNIEnv* env, jobject javaThis) {
+ ScopedFastNativeObjectAccess soa(env);
+ mirror::Reference* const ref = soa.Decode<mirror::Reference*>(javaThis);
+ mirror::Object* const referent =
+ Runtime::Current()->GetHeap()->GetReferenceProcessor()->GetReferent(soa.Self(), ref);
+ return soa.AddLocalReference<jobject>(referent);
+}
+
+static JNINativeMethod gMethods[] = {
+ NATIVE_METHOD(Reference, get, "!()Ljava/lang/Object;"),
+};
+
+void register_java_lang_ref_Reference(JNIEnv* env) {
+ REGISTER_NATIVE_METHODS("java/lang/ref/Reference");
+}
+
+} // namespace art