947 ObjectMonitor* mid = (ObjectMonitor *)(block + i);
948 oop object = (oop)mid->object();
949 if (object != NULL) {
950 closure->do_monitor(mid);
951 }
952 }
953 block = (PaddedEnd<ObjectMonitor> *)block->FreeNext;
954 }
955 }
956
957 // Get the next block in the block list.
958 static inline ObjectMonitor* next(ObjectMonitor* block) {
959 assert(block->object() == CHAINMARKER, "must be a block header");
960 block = block->FreeNext;
961 assert(block == NULL || block->object() == CHAINMARKER, "must be a block header");
962 return block;
963 }
964
965
966 void ObjectSynchronizer::oops_do(OopClosure* f) {
967 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
968 PaddedEnd<ObjectMonitor> * block =
969 (PaddedEnd<ObjectMonitor> *)OrderAccess::load_ptr_acquire(&gBlockList);
970 for (; block != NULL; block = (PaddedEnd<ObjectMonitor> *)next(block)) {
971 assert(block->object() == CHAINMARKER, "must be a block header");
972 for (int i = 1; i < _BLOCKSIZE; i++) {
973 ObjectMonitor* mid = (ObjectMonitor *)&block[i];
974 if (mid->object() != NULL) {
975 f->do_oop((oop*)mid->object_addr());
976 }
977 }
978 }
979 }
980
981
982 // -----------------------------------------------------------------------------
983 // ObjectMonitor Lifecycle
984 // -----------------------
985 // Inflation unlinks monitors from the global gFreeList and
986 // associates them with objects. Deflation -- which occurs at
987 // STW-time -- disassociates idle monitors from objects. Such
988 // scavenged monitors are returned to the gFreeList.
989 //
990 // The global list is protected by gListLock. All the critical sections
991 // are short and operate in constant-time.
992 //
993 // ObjectMonitors reside in type-stable memory (TSM) and are immortal.
994 //
995 // Lifecycle:
996 // -- unassigned and on the global free list
|
947 ObjectMonitor* mid = (ObjectMonitor *)(block + i);
948 oop object = (oop)mid->object();
949 if (object != NULL) {
950 closure->do_monitor(mid);
951 }
952 }
953 block = (PaddedEnd<ObjectMonitor> *)block->FreeNext;
954 }
955 }
956
957 // Get the next block in the block list.
958 static inline ObjectMonitor* next(ObjectMonitor* block) {
959 assert(block->object() == CHAINMARKER, "must be a block header");
960 block = block->FreeNext;
961 assert(block == NULL || block->object() == CHAINMARKER, "must be a block header");
962 return block;
963 }
964
965
966 void ObjectSynchronizer::oops_do(OopClosure* f) {
967 if (MonitorInUseLists) {
968 // When using thread local monitor lists, we only scan the
969 // global used list here (for moribund threads), and
970 // the thread-local monitors in Thread::oops_do().
971 global_used_oops_do(f);
972 } else {
973 global_oops_do(f);
974 }
975 }
976
977 void ObjectSynchronizer::global_oops_do(OopClosure* f) {
978 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
979 PaddedEnd<ObjectMonitor> * block =
980 (PaddedEnd<ObjectMonitor> *)OrderAccess::load_ptr_acquire(&gBlockList);
981 for (; block != NULL; block = (PaddedEnd<ObjectMonitor> *)next(block)) {
982 assert(block->object() == CHAINMARKER, "must be a block header");
983 for (int i = 1; i < _BLOCKSIZE; i++) {
984 ObjectMonitor* mid = (ObjectMonitor *)&block[i];
985 if (mid->object() != NULL) {
986 f->do_oop((oop*)mid->object_addr());
987 }
988 }
989 }
990 }
991
992 void ObjectSynchronizer::global_used_oops_do(OopClosure* f) {
993 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
994 list_oops_do(gOmInUseList, f);
995 }
996
997 void ObjectSynchronizer::thread_local_used_oops_do(Thread* thread, OopClosure* f) {
998 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
999 list_oops_do(thread->omInUseList, f);
1000 }
1001
1002 void ObjectSynchronizer::list_oops_do(ObjectMonitor* list, OopClosure* f) {
1003 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1004 ObjectMonitor* mid;
1005 for (mid = list; mid != NULL; mid = mid->FreeNext) {
1006 if (mid->object() != NULL) {
1007 f->do_oop((oop*)mid->object_addr());
1008 }
1009 }
1010 }
1011
1012
1013 // -----------------------------------------------------------------------------
1014 // ObjectMonitor Lifecycle
1015 // -----------------------
1016 // Inflation unlinks monitors from the global gFreeList and
1017 // associates them with objects. Deflation -- which occurs at
1018 // STW-time -- disassociates idle monitors from objects. Such
1019 // scavenged monitors are returned to the gFreeList.
1020 //
1021 // The global list is protected by gListLock. All the critical sections
1022 // are short and operate in constant-time.
1023 //
1024 // ObjectMonitors reside in type-stable memory (TSM) and are immortal.
1025 //
1026 // Lifecycle:
1027 // -- unassigned and on the global free list
|