1 /*
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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;
1517 _tags = (jlong*)tags;
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 jobject ref = JNIHandles::make_local(JavaThread::current(), o);
1538 _object_results->append(ref);
1539 _tag_results->append((uint64_t)entry->tag());
1540 }
1541 }
1542 }
1543
1544 // return the results from the collection
1545 //
1546 jvmtiError result(jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) {
1547 jvmtiError error;
1548 int count = _object_results->length();
1549 assert(count >= 0, "sanity check");
1550
1551 // if object_result_ptr is not NULL then allocate the result and copy
1552 // in the object references.
1553 if (object_result_ptr != NULL) {
1554 error = _env->Allocate(count * sizeof(jobject), (unsigned char**)object_result_ptr);
1555 if (error != JVMTI_ERROR_NONE) {
1556 return error;
|
1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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;
1518 _tags = (jlong*)tags;
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 // We could be accessing the referent field in a reference
1540 // object. If G1 is enabled then we need to register non-null
1541 // referent with the SATB barrier.
1542 if (UseG1GC) {
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) {
1565 return error;
|