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