1 /*
2 * Copyright (c) 2020, 2023, 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 *
23 */
24
25 #ifndef SHARE_VM_PRIMS_TAGMAPTABLE_HPP
26 #define SHARE_VM_PRIMS_TAGMAPTABLE_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "memory/allocation.hpp"
30 #include "oops/weakHandle.hpp"
31 #include "utilities/resizeableResourceHash.hpp"
32
33 class JvmtiEnv;
34 class JvmtiTagMapKeyClosure;
35
36 // The oop is needed for lookup rather than creating a WeakHandle during
37 // lookup because the HeapWalker may walk soon to be dead objects and
38 // creating a WeakHandle for an otherwise dead object makes G1 unhappy.
39 //
40 // This class is the Key type for inserting in ResizeableResourceHashTable
41 // Its get_hash() and equals() methods are also used for getting the hash
42 // value of a Key and comparing two Keys, respectively.
43 class JvmtiTagMapKey : public CHeapObj<mtServiceability> {
44 WeakHandle _wh;
45 oop _obj; // temporarily hold obj while searching
46 public:
47 JvmtiTagMapKey(oop obj);
48 JvmtiTagMapKey(const JvmtiTagMapKey& src);
49 JvmtiTagMapKey& operator=(const JvmtiTagMapKey&) = delete;
50
51 oop object() const;
52 oop object_no_keepalive() const;
53 void release_weak_handle();
54
55 static unsigned get_hash(const JvmtiTagMapKey& entry) {
56 assert(entry._obj != nullptr, "must lookup obj to hash");
57 return (unsigned)entry._obj->identity_hash();
58 }
59
60 static bool equals(const JvmtiTagMapKey& lhs, const JvmtiTagMapKey& rhs) {
61 oop lhs_obj = lhs._obj != nullptr ? lhs._obj : lhs.object_no_keepalive();
62 oop rhs_obj = rhs._obj != nullptr ? rhs._obj : rhs.object_no_keepalive();
63 return lhs_obj == rhs_obj;
64 }
65 };
66
67 typedef
68 ResizeableResourceHashtable <JvmtiTagMapKey, jlong,
69 AnyObj::C_HEAP, mtServiceability,
70 JvmtiTagMapKey::get_hash,
71 JvmtiTagMapKey::equals> ResizableResourceHT;
72
73 class JvmtiTagMapTable : public CHeapObj<mtServiceability> {
74 private:
75 ResizableResourceHT _table;
76
77 public:
78 JvmtiTagMapTable();
79 ~JvmtiTagMapTable();
80
81 jlong find(oop obj);
82 void add(oop obj, jlong tag);
83
84 void remove(oop obj);
|
1 /*
2 * Copyright (c) 2020, 2024, 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 *
23 */
24
25 #ifndef SHARE_VM_PRIMS_TAGMAPTABLE_HPP
26 #define SHARE_VM_PRIMS_TAGMAPTABLE_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "memory/allocation.hpp"
30 #include "oops/weakHandle.hpp"
31 #include "utilities/resizeableResourceHash.hpp"
32
33 class JvmtiEnv;
34 class JvmtiTagMapKeyClosure;
35
36 // The oop is needed for lookup rather than creating a WeakHandle during
37 // lookup because the HeapWalker may walk soon to be dead objects and
38 // creating a WeakHandle for an otherwise dead object makes G1 unhappy.
39 //
40 // This class is the Key type for inserting in ResizeableResourceHashTable
41 // Its get_hash() and equals() methods are also used for getting the hash
42 // value of a Key and comparing two Keys, respectively.
43 //
44 // Valhalla: Keep just one tag for all equal value objects including heap allocated value objects.
45 // We have to keep a strong reference to each unique value object with a non-zero tag.
46 class JvmtiTagMapKey : public CHeapObj<mtServiceability> {
47 // All equal value objects should have the same tag.
48 // Keep value objects alive (1 copy for each "value") until their tags are removed.
49 union {
50 WeakHandle _wh;
51 OopHandle _h; // for value objects (_is_weak == false)
52 };
53 bool _is_weak;
54 oop _obj; // temporarily hold obj while searching
55 public:
56 JvmtiTagMapKey(oop obj);
57 JvmtiTagMapKey(const JvmtiTagMapKey& src);
58 JvmtiTagMapKey& operator=(const JvmtiTagMapKey&) = delete;
59
60 oop object() const;
61 oop object_no_keepalive() const;
62 void release_handle();
63
64 static unsigned get_hash(const JvmtiTagMapKey& entry);
65 static bool equals(const JvmtiTagMapKey& lhs, const JvmtiTagMapKey& rhs);
66 };
67
68 typedef
69 ResizeableResourceHashtable <JvmtiTagMapKey, jlong,
70 AnyObj::C_HEAP, mtServiceability,
71 JvmtiTagMapKey::get_hash,
72 JvmtiTagMapKey::equals> ResizableResourceHT;
73
74 class JvmtiTagMapTable : public CHeapObj<mtServiceability> {
75 private:
76 ResizableResourceHT _table;
77
78 public:
79 JvmtiTagMapTable();
80 ~JvmtiTagMapTable();
81
82 jlong find(oop obj);
83 void add(oop obj, jlong tag);
84
85 void remove(oop obj);
|