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 ResolvedMethodTable* _the_table;
  63 private:
  64   ResolvedMethodEntry* bucket(int i) {
  65     return (ResolvedMethodEntry*) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket(i);
  66   }
  67 
  68   ResolvedMethodEntry** bucket_addr(int i) {
  69     return (ResolvedMethodEntry**) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket_addr(i);
  70   }
  71 
  72   unsigned int compute_hash(Method* method);
  73 
  74   // need not be locked; no state change
  75   oop lookup(int index, unsigned int hash, Method* method);
  76   oop lookup(Method* method);
  77 
  78   // must be done under ResolvedMethodTable_lock
  79   oop basic_add(Method* method, Handle rmethod_name);
  80 
  81 public:
  82   ResolvedMethodTable();
  83 
  84   static void create_table() {
  85     assert(_the_table == NULL, "One symbol table allowed.");
  86     _the_table = new ResolvedMethodTable();
  87   }
  88 
  89   // Called from java_lang_invoke_ResolvedMethodName
  90   static oop find_method(Method* method);
  91   static oop add_method(Handle rmethod_name);
  92 
  93 #if INCLUDE_JVMTI
  94   // It is called at safepoint only for RedefineClasses
  95   static void adjust_method_entries(bool * trace_name_printed);
  96 #endif // INCLUDE_JVMTI
  97 
  98   // Cleanup cleared entries
  99   static void unlink();
 100 
 101 #ifndef PRODUCT
 102   void print();
 103 #endif
 104   void verify();
 105 };
 106 
 107 #endif // SHARE_VM_PRIMS_RESOLVEDMETHOD_HPP