< prev index next >

src/hotspot/share/prims/jvmtiTagMapTable.hpp

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -38,32 +38,33 @@
  // creating a WeakHandle for an otherwise dead object makes G1 unhappy.
  //
  // This class is the Key type for inserting in ResizeableResourceHashTable
  // Its get_hash() and equals() methods are also used for getting the hash
  // value of a Key and comparing two Keys, respectively.
+ //
+ // Valhalla: Keep just one tag for all equal value objects including heap allocated value objects.
+ // We have to keep a strong reference to each unique value object with a non-zero tag.
  class JvmtiTagMapKey : public CHeapObj<mtServiceability> {
-   WeakHandle _wh;
+   // All equal value objects should have the same tag.
+   // Keep value objects alive (1 copy for each "value") until their tags are removed.
+   union {
+     WeakHandle _wh;
+     OopHandle _h; // for value objects (_is_weak == false)
+   };
+   bool _is_weak;
    oop _obj; // temporarily hold obj while searching
   public:
    JvmtiTagMapKey(oop obj);
    JvmtiTagMapKey(const JvmtiTagMapKey& src);
    JvmtiTagMapKey& operator=(const JvmtiTagMapKey&) = delete;
  
    oop object() const;
    oop object_no_keepalive() const;
-   void release_weak_handle();
- 
-   static unsigned get_hash(const JvmtiTagMapKey& entry) {
-     assert(entry._obj != nullptr, "must lookup obj to hash");
-     return (unsigned)entry._obj->identity_hash();
-   }
+   void release_handle();
  
-   static bool equals(const JvmtiTagMapKey& lhs, const JvmtiTagMapKey& rhs) {
-     oop lhs_obj = lhs._obj != nullptr ? lhs._obj : lhs.object_no_keepalive();
-     oop rhs_obj = rhs._obj != nullptr ? rhs._obj : rhs.object_no_keepalive();
-     return lhs_obj == rhs_obj;
-   }
+   static unsigned get_hash(const JvmtiTagMapKey& entry);
+   static bool equals(const JvmtiTagMapKey& lhs, const JvmtiTagMapKey& rhs);
  };
  
  typedef
  ResizeableResourceHashtable <JvmtiTagMapKey, jlong,
                                AnyObj::C_HEAP, mtServiceability,
< prev index next >