1 /*
   2  * Copyright (c) 2017, 2019, 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_PRIMS_RESOLVEDMETHODTABLE_HPP
  26 #define SHARE_PRIMS_RESOLVEDMETHODTABLE_HPP
  27 
  28 #include "gc/shared/oopStorage.hpp"
  29 #include "gc/shared/oopStorageParState.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "oops/weakHandle.hpp"
  33 #include "utilities/concurrentHashTable.hpp"
  34 #include "utilities/hashtable.hpp"
  35 
  36 class ResolvedMethodTable;
  37 class ResolvedMethodTableConfig;
  38 typedef ConcurrentHashTable<WeakHandle<vm_resolved_method_table_data>, ResolvedMethodTableConfig, mtClass> ResolvedMethodTableHash;
  39 
  40 class ResolvedMethodTable : public AllStatic {
  41   static ResolvedMethodTableHash* _local_table;
  42   static size_t                   _current_size;
  43 
  44   static OopStorage*              _weak_handles;
  45 
  46   static volatile bool            _has_work;
  47 
  48   static volatile size_t          _items_count;
  49   static volatile size_t          _uncleaned_items_count;
  50 
  51 public:
  52   // Initialization
  53   static void create_table();
  54 
  55   static size_t table_size();
  56 
  57   // Lookup and inserts
  58   static oop find_method(const Method* method);
  59   static oop add_method(const Method* method, Handle rmethod_name);
  60 
  61   // Callbacks
  62   static void item_added();
  63   static void item_removed();
  64 
  65   // Cleaning
  66   static bool has_work();
  67 
  68   // GC Support - Backing storage for the oop*s
  69   static OopStorage* weak_storage();
  70 
  71   // Cleaning and table management
  72 
  73   static double get_load_factor();
  74   static double get_dead_factor();
  75 
  76   static void check_concurrent_work();
  77   static void trigger_concurrent_work();
  78   static void do_concurrent_work(JavaThread* jt);
  79 
  80   static void grow(JavaThread* jt);
  81   static void clean_dead_entries(JavaThread* jt);
  82 
  83   // GC Notification
  84 
  85   // Must be called before a parallel walk where objects might die.
  86   static void reset_dead_counter();
  87   // After the parallel walk this method must be called to trigger
  88   // cleaning. Note it might trigger a resize instead.
  89   static void finish_dead_counter();
  90   // If GC uses ParState directly it should add the number of cleared
  91   // entries to this method.
  92   static void inc_dead_counter(size_t ndead);
  93 
  94   // JVMTI Support - It is called at safepoint only for RedefineClasses
  95   JVMTI_ONLY(static void adjust_method_entries(bool * trace_name_printed);)
  96 
  97   // Debugging
  98   static size_t items_count();
  99   static size_t verify_and_compare_entries();
 100 };
 101 
 102 #endif // SHARE_PRIMS_RESOLVEDMETHODTABLE_HPP