1 /*
   2  * Copyright (c) 2017, 2018, 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_RESOLVEDMETHOD_HPP
  26 #define SHARE_VM_PRIMS_RESOLVEDMETHOD_HPP
  27 
  28 #include "oops/symbol.hpp"
  29 #include "oops/weakHandle.hpp"
  30 #include "utilities/hashtable.hpp"
  31 
  32 // Hashtable to record Method* used in ResolvedMethods, via. ResolvedMethod oops.
  33 // This is needed for redefinition to replace Method* with redefined versions.
  34 
  35 // Entry in a ResolvedMethodTable, mapping a ClassLoaderWeakHandle for a single oop of
  36 // java_lang_invoke_ResolvedMethodName which holds JVM Method* in vmtarget.
  37 
  38 class ResolvedMethodEntry : public HashtableEntry<ClassLoaderWeakHandle, mtClass> {
  39  public:
  40   ResolvedMethodEntry* next() const {
  41     return (ResolvedMethodEntry*)HashtableEntry<ClassLoaderWeakHandle, mtClass>::next();
  42   }
  43 
  44   ResolvedMethodEntry** next_addr() {
  45     return (ResolvedMethodEntry**)HashtableEntry<ClassLoaderWeakHandle, mtClass>::next_addr();
  46   }
  47 
  48   oop object();
  49   oop object_no_keepalive();
  50 
  51   void print_on(outputStream* st) const;
  52 };
  53 
  54 class ResolvedMethodTable : public Hashtable<ClassLoaderWeakHandle, mtClass> {
  55   enum Constants {
  56     _table_size  = 1007
  57   };
  58 
  59   static int _oops_removed;
  60   static int _oops_counted;
  61 
  62   static bool _dead_entries;
  63 
  64   static ResolvedMethodTable* _the_table;
  65 private:
  66   ResolvedMethodEntry* bucket(int i) {
  67     return (ResolvedMethodEntry*) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket(i);
  68   }
  69 
  70   ResolvedMethodEntry** bucket_addr(int i) {
  71     return (ResolvedMethodEntry**) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket_addr(i);
  72   }
  73 
  74   unsigned int compute_hash(Method* method);
  75 
  76   // need not be locked; no state change
  77   oop lookup(int index, unsigned int hash, Method* method);
  78   oop lookup(Method* method);
  79 
  80   // must be done under ResolvedMethodTable_lock
  81   oop basic_add(Method* method, Handle rmethod_name);
  82 
  83 public:
  84   ResolvedMethodTable();
  85 
  86   static void create_table() {
  87     assert(_the_table == NULL, "One symbol table allowed.");
  88     _the_table = new ResolvedMethodTable();
  89   }
  90 
  91   // Called from java_lang_invoke_ResolvedMethodName
  92   static oop find_method(Method* method);
  93   static oop add_method(Handle rmethod_name);
  94 
  95   static bool has_work() { return _dead_entries; }
  96   static void trigger_cleanup();
  97 
  98 #if INCLUDE_JVMTI
  99   // It is called at safepoint only for RedefineClasses
 100   static void adjust_method_entries(bool * trace_name_printed);
 101 #endif // INCLUDE_JVMTI
 102 
 103   // Cleanup cleared entries
 104   static void unlink();
 105 
 106 #ifndef PRODUCT
 107   void print();
 108 #endif
 109   void verify();
 110 };
 111 
 112 #endif // SHARE_VM_PRIMS_RESOLVEDMETHOD_HPP