1 /*
2 * Copyright (c) 2005, 2012, 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 #include "precompiled.hpp"
26 #include "classfile/resolutionErrors.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/handles.inline.hpp"
30 #include "runtime/safepoint.hpp"
31 #include "utilities/hashtable.inline.hpp"
32
33 // add new entry to the table
34 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
35 constantPoolHandle pool, int cp_index, Symbol* error)
36 {
37 assert_locked_or_safepoint(SystemDictionary_lock);
38 assert(!pool.is_null() && error != NULL, "adding NULL obj");
39
40 ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error);
41 add_entry(index, entry);
42 }
43
44 // find entry in the table
45 ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
46 constantPoolHandle pool, int cp_index)
47 {
48 assert_locked_or_safepoint(SystemDictionary_lock);
49
50 for (ResolutionErrorEntry *error_probe = bucket(index);
51 error_probe != NULL;
52 error_probe = error_probe->next()) {
53 if (error_probe->hash() == hash && error_probe->pool() == pool()) {
54 return error_probe;;
55 }
56 }
57 return NULL;
58 }
59
60 void ResolutionErrorEntry::set_error(Symbol* e) {
61 assert(e == NULL || _error == NULL, "cannot reset error");
62 _error = e;
63 if (_error != NULL) _error->increment_refcount();
64 }
65
66 // create new error entry
67 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
68 int cp_index, Symbol* error)
69 {
70 ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
71 entry->set_cp_index(cp_index);
72 NOT_PRODUCT(entry->set_error(NULL);)
73 entry->set_error(error);
74
75 return entry;
76 }
77
78 void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
79 // decrement error refcount
80 assert(entry->error() != NULL, "error should be set");
81 entry->error()->decrement_refcount();
82 Hashtable<ConstantPool*, mtClass>::free_entry(entry);
83 }
84
85
86 // create resolution error table
87 ResolutionErrorTable::ResolutionErrorTable(int table_size)
88 : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
89 }
90
91 // RedefineClasses support - remove matching entry of a
92 // constant pool that is going away
93 void ResolutionErrorTable::delete_entry(ConstantPool* c) {
94 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
95 for (int i = 0; i < table_size(); i++) {
96 for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
97 ResolutionErrorEntry* entry = *p;
98 assert(entry->pool() != NULL, "resolution error table is corrupt");
99 if (entry->pool() == c) {
100 *p = entry->next();
101 free_entry(entry);
|
1 /*
2 * Copyright (c) 2005, 2014, 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 #include "precompiled.hpp"
26 #include "classfile/resolutionErrors.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/handles.inline.hpp"
30 #include "runtime/safepoint.hpp"
31 #include "utilities/hashtable.inline.hpp"
32
33 // add new entry to the table
34 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
35 constantPoolHandle pool, int cp_index,
36 Symbol* error, Symbol* message)
37 {
38 assert_locked_or_safepoint(SystemDictionary_lock);
39 assert(!pool.is_null() && error != NULL, "adding NULL obj");
40
41 ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error, message);
42 add_entry(index, entry);
43 }
44
45 // find entry in the table
46 ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
47 constantPoolHandle pool, int cp_index)
48 {
49 assert_locked_or_safepoint(SystemDictionary_lock);
50
51 for (ResolutionErrorEntry *error_probe = bucket(index);
52 error_probe != NULL;
53 error_probe = error_probe->next()) {
54 if (error_probe->hash() == hash && error_probe->pool() == pool()) {
55 return error_probe;;
56 }
57 }
58 return NULL;
59 }
60
61 void ResolutionErrorEntry::set_error(Symbol* e) {
62 assert(e != NULL, "must set a value");
63 _error = e;
64 _error->increment_refcount();
65 }
66
67 void ResolutionErrorEntry::set_message(Symbol* c) {
68 assert(c != NULL, "must set a value");
69 _message = c;
70 _message->increment_refcount();
71 }
72
73 // create new error entry
74 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
75 int cp_index, Symbol* error,
76 Symbol* message)
77 {
78 ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
79 entry->set_cp_index(cp_index);
80 entry->set_error(error);
81 entry->set_message(message);
82
83 return entry;
84 }
85
86 void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
87 // decrement error refcount
88 assert(entry->error() != NULL, "error should be set");
89 entry->error()->decrement_refcount();
90 entry->message()->decrement_refcount();
91 Hashtable<ConstantPool*, mtClass>::free_entry(entry);
92 }
93
94
95 // create resolution error table
96 ResolutionErrorTable::ResolutionErrorTable(int table_size)
97 : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
98 }
99
100 // RedefineClasses support - remove matching entry of a
101 // constant pool that is going away
102 void ResolutionErrorTable::delete_entry(ConstantPool* c) {
103 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
104 for (int i = 0; i < table_size(); i++) {
105 for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
106 ResolutionErrorEntry* entry = *p;
107 assert(entry->pool() != NULL, "resolution error table is corrupt");
108 if (entry->pool() == c) {
109 *p = entry->next();
110 free_entry(entry);
|