34 #include "oops/objArrayKlass.hpp"
35 #include "oops/objArrayOop.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "prims/jvmtiEventController.hpp"
38 #include "prims/jvmtiEventController.inline.hpp"
39 #include "prims/jvmtiExport.hpp"
40 #include "prims/jvmtiImpl.hpp"
41 #include "prims/jvmtiTagMap.hpp"
42 #include "runtime/biasedLocking.hpp"
43 #include "runtime/javaCalls.hpp"
44 #include "runtime/jniHandles.hpp"
45 #include "runtime/mutex.hpp"
46 #include "runtime/mutexLocker.hpp"
47 #include "runtime/reflectionUtils.hpp"
48 #include "runtime/vframe.hpp"
49 #include "runtime/vmThread.hpp"
50 #include "runtime/vm_operations.hpp"
51 #include "services/serviceUtil.hpp"
52 #include "utilities/macros.hpp"
53 #if INCLUDE_ALL_GCS
54 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
55 #include "gc/parallel/parallelScavengeHeap.hpp"
56 #endif // INCLUDE_ALL_GCS
57
58 // JvmtiTagHashmapEntry
59 //
60 // Each entry encapsulates a reference to the tagged object
61 // and the tag value. In addition an entry includes a next pointer which
62 // is used to chain entries together.
63
64 class JvmtiTagHashmapEntry : public CHeapObj<mtInternal> {
65 private:
66 friend class JvmtiTagMap;
67
68 oop _object; // tagged object
69 jlong _tag; // the tag
70 JvmtiTagHashmapEntry* _next; // next on the list
71
72 inline void init(oop object, jlong tag) {
73 _object = object;
74 _tag = tag;
1519 _tag_count = tag_count;
1520 _object_results = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jobject>(1,true);
1521 _tag_results = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<uint64_t>(1,true);
1522 }
1523
1524 ~TagObjectCollector() {
1525 delete _object_results;
1526 delete _tag_results;
1527 }
1528
1529 // for each tagged object check if the tag value matches
1530 // - if it matches then we create a JNI local reference to the object
1531 // and record the reference and tag value.
1532 //
1533 void do_entry(JvmtiTagHashmapEntry* entry) {
1534 for (int i=0; i<_tag_count; i++) {
1535 if (_tags[i] == entry->tag()) {
1536 oop o = entry->object();
1537 assert(o != NULL && Universe::heap()->is_in_reserved(o), "sanity check");
1538 #if INCLUDE_ALL_GCS
1539 if (UseG1GC || UseShenandoahGC) {
1540 // The reference in this tag map could be the only (implicitly weak)
1541 // reference to that object. If we hand it out, we need to keep it live wrt
1542 // SATB marking similar to other j.l.ref.Reference referents.
1543 G1SATBCardTableModRefBS::enqueue(o);
1544 }
1545 #endif
1546 jobject ref = JNIHandles::make_local(JavaThread::current(), o);
1547 _object_results->append(ref);
1548 _tag_results->append((uint64_t)entry->tag());
1549 }
1550 }
1551 }
1552
1553 // return the results from the collection
1554 //
1555 jvmtiError result(jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) {
1556 jvmtiError error;
1557 int count = _object_results->length();
1558 assert(count >= 0, "sanity check");
1559
1560 // if object_result_ptr is not NULL then allocate the result and copy
1561 // in the object references.
1562 if (object_result_ptr != NULL) {
1563 error = _env->Allocate(count * sizeof(jobject), (unsigned char**)object_result_ptr);
1564 if (error != JVMTI_ERROR_NONE) {
|
34 #include "oops/objArrayKlass.hpp"
35 #include "oops/objArrayOop.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "prims/jvmtiEventController.hpp"
38 #include "prims/jvmtiEventController.inline.hpp"
39 #include "prims/jvmtiExport.hpp"
40 #include "prims/jvmtiImpl.hpp"
41 #include "prims/jvmtiTagMap.hpp"
42 #include "runtime/biasedLocking.hpp"
43 #include "runtime/javaCalls.hpp"
44 #include "runtime/jniHandles.hpp"
45 #include "runtime/mutex.hpp"
46 #include "runtime/mutexLocker.hpp"
47 #include "runtime/reflectionUtils.hpp"
48 #include "runtime/vframe.hpp"
49 #include "runtime/vmThread.hpp"
50 #include "runtime/vm_operations.hpp"
51 #include "services/serviceUtil.hpp"
52 #include "utilities/macros.hpp"
53 #if INCLUDE_ALL_GCS
54 #include "gc/parallel/parallelScavengeHeap.hpp"
55 #endif // INCLUDE_ALL_GCS
56
57 // JvmtiTagHashmapEntry
58 //
59 // Each entry encapsulates a reference to the tagged object
60 // and the tag value. In addition an entry includes a next pointer which
61 // is used to chain entries together.
62
63 class JvmtiTagHashmapEntry : public CHeapObj<mtInternal> {
64 private:
65 friend class JvmtiTagMap;
66
67 oop _object; // tagged object
68 jlong _tag; // the tag
69 JvmtiTagHashmapEntry* _next; // next on the list
70
71 inline void init(oop object, jlong tag) {
72 _object = object;
73 _tag = tag;
1518 _tag_count = tag_count;
1519 _object_results = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jobject>(1,true);
1520 _tag_results = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<uint64_t>(1,true);
1521 }
1522
1523 ~TagObjectCollector() {
1524 delete _object_results;
1525 delete _tag_results;
1526 }
1527
1528 // for each tagged object check if the tag value matches
1529 // - if it matches then we create a JNI local reference to the object
1530 // and record the reference and tag value.
1531 //
1532 void do_entry(JvmtiTagHashmapEntry* entry) {
1533 for (int i=0; i<_tag_count; i++) {
1534 if (_tags[i] == entry->tag()) {
1535 oop o = entry->object();
1536 assert(o != NULL && Universe::heap()->is_in_reserved(o), "sanity check");
1537 #if INCLUDE_ALL_GCS
1538 // The reference in this tag map could be the only (implicitly weak)
1539 // reference to that object. If we hand it out, we need to keep it live wrt
1540 // SATB marking similar to other j.l.ref.Reference referents.
1541 oopDesc::bs()->keep_alive_barrier(o);
1542 #endif
1543 jobject ref = JNIHandles::make_local(JavaThread::current(), o);
1544 _object_results->append(ref);
1545 _tag_results->append((uint64_t)entry->tag());
1546 }
1547 }
1548 }
1549
1550 // return the results from the collection
1551 //
1552 jvmtiError result(jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) {
1553 jvmtiError error;
1554 int count = _object_results->length();
1555 assert(count >= 0, "sanity check");
1556
1557 // if object_result_ptr is not NULL then allocate the result and copy
1558 // in the object references.
1559 if (object_result_ptr != NULL) {
1560 error = _env->Allocate(count * sizeof(jobject), (unsigned char**)object_result_ptr);
1561 if (error != JVMTI_ERROR_NONE) {
|