summaryrefslogtreecommitdiff
path: root/runtime/runtime.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/runtime.cc')
-rw-r--r--runtime/runtime.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index d8e857354e..561ada4e2b 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -71,8 +71,10 @@
#include "fault_handler.h"
#include "gc/accounting/card_table-inl.h"
#include "gc/heap.h"
+#include "gc/scoped_gc_critical_section.h"
#include "gc/space/image_space.h"
#include "gc/space/space-inl.h"
+#include "gc/system_weak.h"
#include "handle_scope-inl.h"
#include "image-inl.h"
#include "instrumentation.h"
@@ -473,6 +475,11 @@ void Runtime::SweepSystemWeaks(IsMarkedVisitor* visitor) {
GetMonitorList()->SweepMonitorList(visitor);
GetJavaVM()->SweepJniWeakGlobals(visitor);
GetHeap()->SweepAllocationRecords(visitor);
+
+ // All other generic system-weak holders.
+ for (gc::AbstractSystemWeakHolder* holder : system_weak_holders_) {
+ holder->Sweep(visitor);
+ }
}
bool Runtime::ParseOptions(const RuntimeOptions& raw_options,
@@ -1722,6 +1729,11 @@ void Runtime::DisallowNewSystemWeaks() {
intern_table_->ChangeWeakRootState(gc::kWeakRootStateNoReadsOrWrites);
java_vm_->DisallowNewWeakGlobals();
heap_->DisallowNewAllocationRecords();
+
+ // All other generic system-weak holders.
+ for (gc::AbstractSystemWeakHolder* holder : system_weak_holders_) {
+ holder->Disallow();
+ }
}
void Runtime::AllowNewSystemWeaks() {
@@ -1730,6 +1742,11 @@ void Runtime::AllowNewSystemWeaks() {
intern_table_->ChangeWeakRootState(gc::kWeakRootStateNormal); // TODO: Do this in the sweeping.
java_vm_->AllowNewWeakGlobals();
heap_->AllowNewAllocationRecords();
+
+ // All other generic system-weak holders.
+ for (gc::AbstractSystemWeakHolder* holder : system_weak_holders_) {
+ holder->Allow();
+ }
}
void Runtime::BroadcastForNewSystemWeaks() {
@@ -1740,6 +1757,11 @@ void Runtime::BroadcastForNewSystemWeaks() {
intern_table_->BroadcastForNewInterns();
java_vm_->BroadcastForNewWeakGlobals();
heap_->BroadcastForNewAllocationRecords();
+
+ // All other generic system-weak holders.
+ for (gc::AbstractSystemWeakHolder* holder : system_weak_holders_) {
+ holder->Broadcast();
+ }
}
void Runtime::SetInstructionSet(InstructionSet instruction_set) {
@@ -2084,4 +2106,21 @@ char** Runtime::EnvSnapshot::GetSnapshot() const {
return c_env_vector_.get();
}
+void Runtime::AddSystemWeakHolder(gc::AbstractSystemWeakHolder* holder) {
+ gc::ScopedGCCriticalSection gcs(Thread::Current(),
+ gc::kGcCauseAddRemoveSystemWeakHolder,
+ gc::kCollectorTypeAddRemoveSystemWeakHolder);
+ system_weak_holders_.push_back(holder);
+}
+
+void Runtime::RemoveSystemWeakHolder(gc::AbstractSystemWeakHolder* holder) {
+ gc::ScopedGCCriticalSection gcs(Thread::Current(),
+ gc::kGcCauseAddRemoveSystemWeakHolder,
+ gc::kCollectorTypeAddRemoveSystemWeakHolder);
+ auto it = std::find(system_weak_holders_.begin(), system_weak_holders_.end(), holder);
+ if (it != system_weak_holders_.end()) {
+ system_weak_holders_.erase(it);
+ }
+}
+
} // namespace art