Mercurial > hg > graal-compiler
comparison src/share/vm/prims/jvmtiTagMap.cpp @ 4137:04b9a2566eec
Merge with hsx23/hotspot.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 21:40:27 +0100 |
parents | 88dce6a60ac8 |
children | 2b150750d53d |
comparison
equal
deleted
inserted
replaced
3737:9dc19b7d89a3 | 4137:04b9a2566eec |
---|---|
1645 class ObjectMarker : AllStatic { | 1645 class ObjectMarker : AllStatic { |
1646 private: | 1646 private: |
1647 // saved headers | 1647 // saved headers |
1648 static GrowableArray<oop>* _saved_oop_stack; | 1648 static GrowableArray<oop>* _saved_oop_stack; |
1649 static GrowableArray<markOop>* _saved_mark_stack; | 1649 static GrowableArray<markOop>* _saved_mark_stack; |
1650 static bool _needs_reset; // do we need to reset mark bits? | |
1650 | 1651 |
1651 public: | 1652 public: |
1652 static void init(); // initialize | 1653 static void init(); // initialize |
1653 static void done(); // clean-up | 1654 static void done(); // clean-up |
1654 | 1655 |
1655 static inline void mark(oop o); // mark an object | 1656 static inline void mark(oop o); // mark an object |
1656 static inline bool visited(oop o); // check if object has been visited | 1657 static inline bool visited(oop o); // check if object has been visited |
1658 | |
1659 static inline bool needs_reset() { return _needs_reset; } | |
1660 static inline void set_needs_reset(bool v) { _needs_reset = v; } | |
1657 }; | 1661 }; |
1658 | 1662 |
1659 GrowableArray<oop>* ObjectMarker::_saved_oop_stack = NULL; | 1663 GrowableArray<oop>* ObjectMarker::_saved_oop_stack = NULL; |
1660 GrowableArray<markOop>* ObjectMarker::_saved_mark_stack = NULL; | 1664 GrowableArray<markOop>* ObjectMarker::_saved_mark_stack = NULL; |
1665 bool ObjectMarker::_needs_reset = true; // need to reset mark bits by default | |
1661 | 1666 |
1662 // initialize ObjectMarker - prepares for object marking | 1667 // initialize ObjectMarker - prepares for object marking |
1663 void ObjectMarker::init() { | 1668 void ObjectMarker::init() { |
1664 assert(Thread::current()->is_VM_thread(), "must be VMThread"); | 1669 assert(Thread::current()->is_VM_thread(), "must be VMThread"); |
1665 | 1670 |
1678 // Object marking is done so restore object headers | 1683 // Object marking is done so restore object headers |
1679 void ObjectMarker::done() { | 1684 void ObjectMarker::done() { |
1680 // iterate over all objects and restore the mark bits to | 1685 // iterate over all objects and restore the mark bits to |
1681 // their initial value | 1686 // their initial value |
1682 RestoreMarksClosure blk; | 1687 RestoreMarksClosure blk; |
1683 Universe::heap()->object_iterate(&blk); | 1688 if (needs_reset()) { |
1689 Universe::heap()->object_iterate(&blk); | |
1690 } else { | |
1691 // We don't need to reset mark bits on this call, but reset the | |
1692 // flag to the default for the next call. | |
1693 set_needs_reset(true); | |
1694 } | |
1684 | 1695 |
1685 // When sharing is enabled we need to restore the headers of the objects | 1696 // When sharing is enabled we need to restore the headers of the objects |
1686 // in the readwrite space too. | 1697 // in the readwrite space too. |
1687 if (UseSharedSpaces) { | 1698 if (UseSharedSpaces) { |
1688 GenCollectedHeap* gch = GenCollectedHeap::heap(); | 1699 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3021 } | 3032 } |
3022 return true; | 3033 return true; |
3023 } | 3034 } |
3024 | 3035 |
3025 | 3036 |
3026 // collects all simple (non-stack) roots. | 3037 // Collects all simple (non-stack) roots except for threads; |
3038 // threads are handled in collect_stack_roots() as an optimization. | |
3027 // if there's a heap root callback provided then the callback is | 3039 // if there's a heap root callback provided then the callback is |
3028 // invoked for each simple root. | 3040 // invoked for each simple root. |
3029 // if an object reference callback is provided then all simple | 3041 // if an object reference callback is provided then all simple |
3030 // roots are pushed onto the marking stack so that they can be | 3042 // roots are pushed onto the marking stack so that they can be |
3031 // processed later | 3043 // processed later |
3052 ObjectSynchronizer::oops_do(&blk); | 3064 ObjectSynchronizer::oops_do(&blk); |
3053 if (blk.stopped()) { | 3065 if (blk.stopped()) { |
3054 return false; | 3066 return false; |
3055 } | 3067 } |
3056 | 3068 |
3057 // Threads | 3069 // threads are now handled in collect_stack_roots() |
3058 for (JavaThread* thread = Threads::first(); thread != NULL ; thread = thread->next()) { | |
3059 oop threadObj = thread->threadObj(); | |
3060 if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) { | |
3061 bool cont = CallbackInvoker::report_simple_root(JVMTI_HEAP_REFERENCE_THREAD, threadObj); | |
3062 if (!cont) { | |
3063 return false; | |
3064 } | |
3065 } | |
3066 } | |
3067 | 3070 |
3068 // Other kinds of roots maintained by HotSpot | 3071 // Other kinds of roots maintained by HotSpot |
3069 // Many of these won't be visible but others (such as instances of important | 3072 // Many of these won't be visible but others (such as instances of important |
3070 // exceptions) will be visible. | 3073 // exceptions) will be visible. |
3071 blk.set_kind(JVMTI_HEAP_REFERENCE_OTHER); | 3074 blk.set_kind(JVMTI_HEAP_REFERENCE_OTHER); |
3173 } | 3176 } |
3174 return true; | 3177 return true; |
3175 } | 3178 } |
3176 | 3179 |
3177 | 3180 |
3178 // collects all stack roots - for each thread it walks the execution | 3181 // Collects the simple roots for all threads and collects all |
3182 // stack roots - for each thread it walks the execution | |
3179 // stack to find all references and local JNI refs. | 3183 // stack to find all references and local JNI refs. |
3180 inline bool VM_HeapWalkOperation::collect_stack_roots() { | 3184 inline bool VM_HeapWalkOperation::collect_stack_roots() { |
3181 JNILocalRootsClosure blk; | 3185 JNILocalRootsClosure blk; |
3182 for (JavaThread* thread = Threads::first(); thread != NULL ; thread = thread->next()) { | 3186 for (JavaThread* thread = Threads::first(); thread != NULL ; thread = thread->next()) { |
3183 oop threadObj = thread->threadObj(); | 3187 oop threadObj = thread->threadObj(); |
3184 if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) { | 3188 if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) { |
3189 // Collect the simple root for this thread before we | |
3190 // collect its stack roots | |
3191 if (!CallbackInvoker::report_simple_root(JVMTI_HEAP_REFERENCE_THREAD, | |
3192 threadObj)) { | |
3193 return false; | |
3194 } | |
3185 if (!collect_stack_roots(thread, &blk)) { | 3195 if (!collect_stack_roots(thread, &blk)) { |
3186 return false; | 3196 return false; |
3187 } | 3197 } |
3188 } | 3198 } |
3189 } | 3199 } |
3233 | 3243 |
3234 assert(visit_stack()->is_empty(), "visit stack must be empty"); | 3244 assert(visit_stack()->is_empty(), "visit stack must be empty"); |
3235 | 3245 |
3236 // the heap walk starts with an initial object or the heap roots | 3246 // the heap walk starts with an initial object or the heap roots |
3237 if (initial_object().is_null()) { | 3247 if (initial_object().is_null()) { |
3248 // If either collect_stack_roots() or collect_simple_roots() | |
3249 // returns false at this point, then there are no mark bits | |
3250 // to reset. | |
3251 ObjectMarker::set_needs_reset(false); | |
3252 | |
3253 // Calling collect_stack_roots() before collect_simple_roots() | |
3254 // can result in a big performance boost for an agent that is | |
3255 // focused on analyzing references in the thread stacks. | |
3256 if (!collect_stack_roots()) return; | |
3257 | |
3238 if (!collect_simple_roots()) return; | 3258 if (!collect_simple_roots()) return; |
3239 if (!collect_stack_roots()) return; | 3259 |
3260 // no early return so enable heap traversal to reset the mark bits | |
3261 ObjectMarker::set_needs_reset(true); | |
3240 } else { | 3262 } else { |
3241 visit_stack()->push(initial_object()()); | 3263 visit_stack()->push(initial_object()()); |
3242 } | 3264 } |
3243 | 3265 |
3244 // object references required | 3266 // object references required |