src/share/vm/classfile/resolutionErrors.cpp

Mon, 05 May 2014 19:53:00 -0400

author
coleenp
date
Mon, 05 May 2014 19:53:00 -0400
changeset 9966
baf9f57c9b46
parent 4037
da91efe96a93
child 10015
eb7ce841ccec
permissions
-rw-r--r--

8023697: failed class resolution reports different class name in detail message for the first and subsequent times
Summary: Cache detail message when we cache exception for constant pool resolution.
Reviewed-by: acorn, twisti, jrose

duke@435 1 /*
coleenp@9966 2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/resolutionErrors.hpp"
stefank@2314 27 #include "memory/resourceArea.hpp"
stefank@2314 28 #include "oops/oop.inline.hpp"
stefank@2314 29 #include "runtime/handles.inline.hpp"
stefank@2314 30 #include "runtime/safepoint.hpp"
stefank@2314 31 #include "utilities/hashtable.inline.hpp"
duke@435 32
duke@435 33 // add new entry to the table
duke@435 34 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
coleenp@9966 35 constantPoolHandle pool, int cp_index,
coleenp@9966 36 Symbol* error, Symbol* message)
duke@435 37 {
duke@435 38 assert_locked_or_safepoint(SystemDictionary_lock);
coleenp@2497 39 assert(!pool.is_null() && error != NULL, "adding NULL obj");
duke@435 40
coleenp@9966 41 ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error, message);
duke@435 42 add_entry(index, entry);
duke@435 43 }
duke@435 44
duke@435 45 // find entry in the table
duke@435 46 ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
duke@435 47 constantPoolHandle pool, int cp_index)
duke@435 48 {
duke@435 49 assert_locked_or_safepoint(SystemDictionary_lock);
duke@435 50
duke@435 51 for (ResolutionErrorEntry *error_probe = bucket(index);
duke@435 52 error_probe != NULL;
duke@435 53 error_probe = error_probe->next()) {
duke@435 54 if (error_probe->hash() == hash && error_probe->pool() == pool()) {
duke@435 55 return error_probe;;
duke@435 56 }
duke@435 57 }
duke@435 58 return NULL;
duke@435 59 }
duke@435 60
coleenp@2497 61 void ResolutionErrorEntry::set_error(Symbol* e) {
coleenp@9966 62 assert(e != NULL, "must set a value");
coleenp@2497 63 _error = e;
coleenp@9966 64 _error->increment_refcount();
coleenp@9966 65 }
coleenp@9966 66
coleenp@9966 67 void ResolutionErrorEntry::set_message(Symbol* c) {
coleenp@9966 68 assert(c != NULL, "must set a value");
coleenp@9966 69 _message = c;
coleenp@9966 70 _message->increment_refcount();
coleenp@2497 71 }
coleenp@2497 72
duke@435 73 // create new error entry
coleenp@4037 74 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
coleenp@9966 75 int cp_index, Symbol* error,
coleenp@9966 76 Symbol* message)
duke@435 77 {
coleenp@4037 78 ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
duke@435 79 entry->set_cp_index(cp_index);
duke@435 80 entry->set_error(error);
coleenp@9966 81 entry->set_message(message);
duke@435 82
duke@435 83 return entry;
duke@435 84 }
duke@435 85
coleenp@2497 86 void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
coleenp@2497 87 // decrement error refcount
coleenp@2497 88 assert(entry->error() != NULL, "error should be set");
coleenp@2497 89 entry->error()->decrement_refcount();
coleenp@9966 90 entry->message()->decrement_refcount();
coleenp@4037 91 Hashtable<ConstantPool*, mtClass>::free_entry(entry);
coleenp@2497 92 }
coleenp@2497 93
coleenp@2497 94
duke@435 95 // create resolution error table
duke@435 96 ResolutionErrorTable::ResolutionErrorTable(int table_size)
coleenp@4037 97 : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
duke@435 98 }
duke@435 99
coleenp@4037 100 // RedefineClasses support - remove matching entry of a
coleenp@4037 101 // constant pool that is going away
coleenp@4037 102 void ResolutionErrorTable::delete_entry(ConstantPool* c) {
coleenp@4037 103 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
duke@435 104 for (int i = 0; i < table_size(); i++) {
coleenp@4037 105 for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
coleenp@4037 106 ResolutionErrorEntry* entry = *p;
coleenp@4037 107 assert(entry->pool() != NULL, "resolution error table is corrupt");
coleenp@4037 108 if (entry->pool() == c) {
coleenp@4037 109 *p = entry->next();
coleenp@4037 110 free_entry(entry);
coleenp@4037 111 } else {
coleenp@4037 112 p = entry->next_addr();
coleenp@4037 113 }
duke@435 114 }
duke@435 115 }
duke@435 116 }
duke@435 117
duke@435 118
duke@435 119 // Remove unloaded entries from the table
coleenp@4037 120 void ResolutionErrorTable::purge_resolution_errors() {
jcoomes@1844 121 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
duke@435 122 for (int i = 0; i < table_size(); i++) {
duke@435 123 for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
duke@435 124 ResolutionErrorEntry* entry = *p;
coleenp@4037 125 assert(entry->pool() != (ConstantPool*)NULL, "resolution error table is corrupt");
coleenp@4037 126 ConstantPool* pool = entry->pool();
coleenp@4037 127 assert(pool->pool_holder() != NULL, "Constant pool without a class?");
coleenp@4037 128 ClassLoaderData* loader_data =
coleenp@4037 129 pool->pool_holder()->class_loader_data();
coleenp@4037 130 if (!loader_data->is_unloading()) {
duke@435 131 p = entry->next_addr();
duke@435 132 } else {
duke@435 133 *p = entry->next();
duke@435 134 free_entry(entry);
duke@435 135 }
duke@435 136 }
duke@435 137 }
duke@435 138 }

mercurial