summaryrefslogtreecommitdiffstats
path: root/runtime/entrypoints/quick
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2014-03-02 13:28:37 -0800
committerMathieu Chartier <mathieuc@google.com>2014-03-03 17:08:30 -0800
commitd889178ec78930538d9d6a66c3df9ee9afaffbb4 (patch)
tree6fa250bdadcdfc1702f57500e618b51df6d46828 /runtime/entrypoints/quick
parent06c09f6d79e037ee00113d6289ef98226680797d (diff)
downloadart-d889178ec78930538d9d6a66c3df9ee9afaffbb4.zip
art-d889178ec78930538d9d6a66c3df9ee9afaffbb4.tar.gz
art-d889178ec78930538d9d6a66c3df9ee9afaffbb4.tar.bz2
Guard entrypoint changing by runtime shutdown lock.
There was a race when we changed the allocation entrypoints where a new thread would be starting (Thread::Init) and initialize to the wrong entrypoints. Guarding allocation entrypoint changing with the runtime shutdown lock fixes this race condition since Thread::Init is only called with the runtime shutdown lock held. Bug: 13250963 Change-Id: I8eb209c124b6bf17020de874e1b0083f158b8200
Diffstat (limited to 'runtime/entrypoints/quick')
-rw-r--r--runtime/entrypoints/quick/quick_alloc_entrypoints.cc88
-rw-r--r--runtime/entrypoints/quick/quick_alloc_entrypoints.h44
2 files changed, 132 insertions, 0 deletions
diff --git a/runtime/entrypoints/quick/quick_alloc_entrypoints.cc b/runtime/entrypoints/quick/quick_alloc_entrypoints.cc
index 2e1b69d..ccc0f3d 100644
--- a/runtime/entrypoints/quick/quick_alloc_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_alloc_entrypoints.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "entrypoints/quick/quick_alloc_entrypoints.h"
+
#include "callee_save_frame.h"
#include "entrypoints/entrypoint_utils.h"
#include "mirror/art_method-inl.h"
@@ -104,4 +106,90 @@ GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(RosAlloc, gc::kAllocatorTypeRosAlloc)
GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(BumpPointer, gc::kAllocatorTypeBumpPointer)
GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(TLAB, gc::kAllocatorTypeTLAB)
+#define GENERATE_ENTRYPOINTS(suffix) \
+extern "C" void* art_quick_alloc_array##suffix(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_alloc_array_resolved##suffix(void* klass, void*, int32_t); \
+extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \
+extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \
+extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \
+extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \
+extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_alloc_array_resolved##suffix##_instrumented(void* klass, void*, int32_t); \
+extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \
+extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \
+extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \
+extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \
+extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
+extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
+void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
+ if (instrumented) { \
+ qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
+ qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix##_instrumented; \
+ qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
+ qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
+ qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \
+ qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \
+ qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
+ qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
+ qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
+ } else { \
+ qpoints->pAllocArray = art_quick_alloc_array##suffix; \
+ qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix; \
+ qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
+ qpoints->pAllocObject = art_quick_alloc_object##suffix; \
+ qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \
+ qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \
+ qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
+ qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
+ qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
+ } \
+}
+
+// Generate the entrypoint functions.
+GENERATE_ENTRYPOINTS(_dlmalloc);
+GENERATE_ENTRYPOINTS(_rosalloc);
+GENERATE_ENTRYPOINTS(_bump_pointer);
+GENERATE_ENTRYPOINTS(_tlab);
+
+static bool entry_points_instrumented = false;
+static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc;
+
+void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
+ entry_points_allocator = allocator;
+}
+
+void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
+ entry_points_instrumented = instrumented;
+}
+
+void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
+ switch (entry_points_allocator) {
+ case gc::kAllocatorTypeDlMalloc: {
+ SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented);
+ break;
+ }
+ case gc::kAllocatorTypeRosAlloc: {
+ SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented);
+ break;
+ }
+ case gc::kAllocatorTypeBumpPointer: {
+ CHECK(kMovingCollector);
+ SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
+ break;
+ }
+ case gc::kAllocatorTypeTLAB: {
+ CHECK(kMovingCollector);
+ SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
+ break;
+ }
+ default: {
+ LOG(FATAL) << "Unimplemented";
+ }
+ }
+}
+
} // namespace art
diff --git a/runtime/entrypoints/quick/quick_alloc_entrypoints.h b/runtime/entrypoints/quick/quick_alloc_entrypoints.h
new file mode 100644
index 0000000..7fd3fe9
--- /dev/null
+++ b/runtime/entrypoints/quick/quick_alloc_entrypoints.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_ALLOC_ENTRYPOINTS_H_
+#define ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_ALLOC_ENTRYPOINTS_H_
+
+#include "gc/heap.h"
+#include "quick_entrypoints.h"
+
+namespace art {
+
+namespace gc {
+enum AllocatorType;
+} // namespace gc
+
+void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints);
+
+// Runtime shutdown lock is necessary to prevent races in thread initialization. When the thread is
+// starting it doesn't hold the mutator lock until after it has been added to the thread list.
+// However, Thread::Init is guarded by the runtime shutdown lock, so we can prevent these races by
+// holding the runtime shutdown lock and the mutator lock when we update the entrypoints.
+
+void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator)
+ EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::runtime_shutdown_lock_);
+
+void SetQuickAllocEntryPointsInstrumented(bool instrumented)
+ EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::runtime_shutdown_lock_);
+
+} // namespace art
+
+#endif // ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_ALLOC_ENTRYPOINTS_H_