1 /* 2 * Copyright (c) 2005, 2020, 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 31 class 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. 40 const int CPCACHE_INDEX_MANGLE_VALUE = 1000000; 41 42 class ResolutionErrorTable : public Hashtable<ConstantPool*, mtClass> { 43 44 public: 45 ResolutionErrorTable(int table_size); 46 47 ResolutionErrorEntry* new_entry(int hash, ConstantPool* pool, int cp_index, 48 Symbol* error, Symbol* message); 49 ResolutionErrorEntry* new_entry(int hash, ConstantPool* pool, int cp_index, 50 const char* message); 51 void free_entry(ResolutionErrorEntry *entry); 52 53 ResolutionErrorEntry* bucket(int i) { 54 return (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::bucket(i); 55 } 56 57 ResolutionErrorEntry** bucket_addr(int i) { 58 return (ResolutionErrorEntry**)Hashtable<ConstantPool*, mtClass>::bucket_addr(i); 59 } 60 61 void add_entry(int index, ResolutionErrorEntry* new_entry) { 62 Hashtable<ConstantPool*, mtClass>::add_entry(index, 63 (HashtableEntry<ConstantPool*, mtClass>*)new_entry); 64 } 65 66 void add_entry(int index, unsigned int hash, 67 const constantPoolHandle& pool, int which, Symbol* error, Symbol* message); 68 69 void add_entry(int index, unsigned int hash, 70 const constantPoolHandle& pool, int which, const char* message); 71 72 // find error given the constant pool and constant pool index 73 ResolutionErrorEntry* find_entry(int index, unsigned int hash, 74 const constantPoolHandle& pool, int cp_index); 75 76 77 unsigned int compute_hash(const constantPoolHandle& pool, int cp_index) { 78 return (unsigned int) pool->identity_hash() + cp_index; 79 } 80 81 // purges unloaded entries from the table 82 void purge_resolution_errors(); 83 84 // RedefineClasses support - remove obsolete constant pool entry 85 void delete_entry(ConstantPool* c); 86 87 // This function is used to encode an index to differentiate it from a 88 // constant pool index. It assumes it is being called with a cpCache index 89 // (that is less than 0). 90 static int encode_cpcache_index(int index) { 91 assert(index < 0, "Unexpected non-negative cpCache index"); 92 return index + CPCACHE_INDEX_MANGLE_VALUE; 93 } 94 }; 95 96 97 class ResolutionErrorEntry : public HashtableEntry<ConstantPool*, mtClass> { 98 private: 99 int _cp_index; 100 Symbol* _error; 101 Symbol* _message; 102 const char* _nest_host_error; 103 104 public: 105 ConstantPool* pool() const { return literal(); } 106 107 int cp_index() const { return _cp_index; } 108 void set_cp_index(int cp_index) { _cp_index = cp_index; } 109 110 Symbol* error() const { return _error; } 111 void set_error(Symbol* e); 112 113 Symbol* message() const { return _message; } 114 void set_message(Symbol* c); 115 116 const char* nest_host_error() const { return _nest_host_error; } 117 void set_nest_host_error(const char* message); 118 119 ResolutionErrorEntry* next() const { 120 return (ResolutionErrorEntry*)HashtableEntry<ConstantPool*, mtClass>::next(); 121 } 122 123 ResolutionErrorEntry** next_addr() { 124 return (ResolutionErrorEntry**)HashtableEntry<ConstantPool*, mtClass>::next_addr(); 125 } 126 }; 127 128 #endif // SHARE_CLASSFILE_RESOLUTIONERRORS_HPP