1/*
2 * Copyright (c) 2005, 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_CLASSFILE_RESOLUTIONERRORS_HPP
26#define SHARE_CLASSFILE_RESOLUTIONERRORS_HPP
27
28#include "oops/constantPool.hpp"
29#include "utilities/hashtable.hpp"
30
31class ResolutionErrorEntry;
32
33// ResolutionError objects are used to record errors encountered during
34// constant pool resolution (JVMS 5.4.3).
35
36// This value is added to the cpCache index of an invokedynamic instruction when
37// storing the resolution error resulting from that invokedynamic instruction.
38// This prevents issues where the cpCache index is the same as the constant pool
39// index of another entry in the table.
40const int CPCACHE_INDEX_MANGLE_VALUE = 1000000;
41
42class ResolutionErrorTable : public Hashtable<ConstantPool*, mtClass> {
43
44public:
45 ResolutionErrorTable(int table_size);
46
47 ResolutionErrorEntry* new_entry(int hash, ConstantPool* pool, int cp_index,
48 Symbol* error, Symbol* message);
49 void free_entry(ResolutionErrorEntry *entry);
50
51 ResolutionErrorEntry* bucket(int i) {
52 return (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::bucket(i);
53 }
54
55 ResolutionErrorEntry** bucket_addr(int i) {
56 return (ResolutionErrorEntry**)Hashtable<ConstantPool*, mtClass>::bucket_addr(i);
57 }
58
59 void add_entry(int index, ResolutionErrorEntry* new_entry) {
60 Hashtable<ConstantPool*, mtClass>::add_entry(index,
61 (HashtableEntry<ConstantPool*, mtClass>*)new_entry);
62 }
63
64 void add_entry(int index, unsigned int hash,
65 const constantPoolHandle& pool, int which, Symbol* error, Symbol* message);
66
67
68 // find error given the constant pool and constant pool index
69 ResolutionErrorEntry* find_entry(int index, unsigned int hash,
70 const constantPoolHandle& pool, int cp_index);
71
72
73 unsigned int compute_hash(const constantPoolHandle& pool, int cp_index) {
74 return (unsigned int) pool->identity_hash() + cp_index;
75 }
76
77 // purges unloaded entries from the table
78 void purge_resolution_errors();
79
80 // RedefineClasses support - remove obsolete constant pool entry
81 void delete_entry(ConstantPool* c);
82
83 // This function is used to encode an index to differentiate it from a
84 // constant pool index. It assumes it is being called with a cpCache index
85 // (that is less than 0).
86 static int encode_cpcache_index(int index) {
87 assert(index < 0, "Unexpected non-negative cpCache index");
88 return index + CPCACHE_INDEX_MANGLE_VALUE;
89 }
90};
91
92
93class ResolutionErrorEntry : public HashtableEntry<ConstantPool*, mtClass> {
94 private:
95 int _cp_index;
96 Symbol* _error;
97 Symbol* _message;
98
99 public:
100 ConstantPool* pool() const { return literal(); }
101
102 int cp_index() const { return _cp_index; }
103 void set_cp_index(int cp_index) { _cp_index = cp_index; }
104
105 Symbol* error() const { return _error; }
106 void set_error(Symbol* e);
107
108 Symbol* message() const { return _message; }
109 void set_message(Symbol* c);
110
111 ResolutionErrorEntry* next() const {
112 return (ResolutionErrorEntry*)HashtableEntry<ConstantPool*, mtClass>::next();
113 }
114
115 ResolutionErrorEntry** next_addr() {
116 return (ResolutionErrorEntry**)HashtableEntry<ConstantPool*, mtClass>::next_addr();
117 }
118};
119
120#endif // SHARE_CLASSFILE_RESOLUTIONERRORS_HPP
121