annotate src/share/vm/classfile/javaAssertions.cpp @ 2426:1d1603768966

7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
author trims
date Tue, 05 Apr 2011 14:12:31 -0700
parents 3582bf76420e
children d2a62e0f25eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2177
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/javaAssertions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "classfile/javaClasses.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "classfile/vmSymbols.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "memory/oopFactory.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/handles.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 bool JavaAssertions::_userDefault = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 bool JavaAssertions::_sysDefault = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 JavaAssertions::OptionList* JavaAssertions::_classes = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 JavaAssertions::OptionList* JavaAssertions::_packages = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 JavaAssertions::OptionList::OptionList(const char* name, bool enabled,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 OptionList* next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 assert(name != 0, "need a name");
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _enabled = enabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _next = next;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 int JavaAssertions::OptionList::count(OptionList* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 int rc;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 for (rc = 0; p != 0; p = p->next(), ++rc) /* empty */;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 return rc;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void JavaAssertions::addOption(const char* name, bool enable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 assert(name != 0, "must have a name");
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Copy the name. The storage needs to exist for the the lifetime of the vm;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // it is never freed, so will be leaked (along with other option strings -
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // e.g., bootclasspath) if a process creates/destroys multiple VMs.
a61af66fc99e Initial load
duke
parents:
diff changeset
60 int len = (int)strlen(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 char *name_copy = NEW_C_HEAP_ARRAY(char, len + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 strcpy(name_copy, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Figure out which list the new item should go on. Names that end in "..."
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // go on the package tree list.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 OptionList** head = &_classes;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (len >= 3 && strcmp(name_copy + len - 3, "...") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Delete the "...".
a61af66fc99e Initial load
duke
parents:
diff changeset
69 len -= 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 name_copy[len] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
71 head = &_packages;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // Convert class/package names to internal format. Will have to convert back
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // when copying to java in createJavaAssertionStatusDirectives, but that
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // should happen only once. Alternative would require that
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // JVM_DesiredAssertionStatus pass the external_name() to
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // JavaAssertion::enabled(), but that is done once per loaded class.
a61af66fc99e Initial load
duke
parents:
diff changeset
79 for (int i = 0; i < len; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (name_copy[i] == '.') name_copy[i] = '/';
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (TraceJavaAssertions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 tty->print_cr("JavaAssertions: adding %s %s=%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
85 head == &_classes ? "class" : "package",
a61af66fc99e Initial load
duke
parents:
diff changeset
86 name_copy[0] != '\0' ? name_copy : "'default'",
a61af66fc99e Initial load
duke
parents:
diff changeset
87 enable);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Prepend a new item to the list. Items added later take precedence, so
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // prepending allows us to stop searching the list after the first match.
a61af66fc99e Initial load
duke
parents:
diff changeset
92 *head = new OptionList(name_copy, enable, *head);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 oop JavaAssertions::createAssertionStatusDirectives(TRAPS) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
96 Symbol* asd_sym = vmSymbols::java_lang_AssertionStatusDirectives();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
97 klassOop k = SystemDictionary::resolve_or_fail(asd_sym, true, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 instanceKlassHandle asd_klass (THREAD, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 asd_klass->initialize(CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Handle h = asd_klass->allocate_instance_handle(CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 int len;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 typeArrayOop t;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 len = OptionList::count(_packages);
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 0
diff changeset
105 objArrayOop pn = oopFactory::new_objArray(SystemDictionary::String_klass(), len, CHECK_NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 objArrayHandle pkgNames (THREAD, pn);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 t = oopFactory::new_typeArray(T_BOOLEAN, len, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 typeArrayHandle pkgEnabled(THREAD, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 fillJavaArrays(_packages, len, pkgNames, pkgEnabled, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 len = OptionList::count(_classes);
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 0
diff changeset
112 objArrayOop cn = oopFactory::new_objArray(SystemDictionary::String_klass(), len, CHECK_NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113 objArrayHandle classNames (THREAD, cn);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 t = oopFactory::new_typeArray(T_BOOLEAN, len, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 typeArrayHandle classEnabled(THREAD, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 fillJavaArrays(_classes, len, classNames, classEnabled, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 java_lang_AssertionStatusDirectives::set_packages(h(), pkgNames());
a61af66fc99e Initial load
duke
parents:
diff changeset
119 java_lang_AssertionStatusDirectives::set_packageEnabled(h(), pkgEnabled());
a61af66fc99e Initial load
duke
parents:
diff changeset
120 java_lang_AssertionStatusDirectives::set_classes(h(), classNames());
a61af66fc99e Initial load
duke
parents:
diff changeset
121 java_lang_AssertionStatusDirectives::set_classEnabled(h(), classEnabled());
a61af66fc99e Initial load
duke
parents:
diff changeset
122 java_lang_AssertionStatusDirectives::set_deflt(h(), userClassDefault());
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return h();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void JavaAssertions::fillJavaArrays(const OptionList* p, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
127 objArrayHandle names, typeArrayHandle enabled, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Fill in the parallel names and enabled (boolean) arrays. Start at the end
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // of the array and work backwards, so the order of items in the arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // matches the order on the command line (the list is in reverse order, since
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // it was created by prepending successive items from the command line).
a61af66fc99e Initial load
duke
parents:
diff changeset
132 int index;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 for (index = len - 1; p != 0; p = p->next(), --index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 assert(index >= 0, "length does not match list");
a61af66fc99e Initial load
duke
parents:
diff changeset
135 Handle s = java_lang_String::create_from_str(p->name(), CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 s = java_lang_String::char_converter(s, '/', '.', CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 names->obj_at_put(index, s());
a61af66fc99e Initial load
duke
parents:
diff changeset
138 enabled->bool_at_put(index, p->enabled());
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 assert(index == -1, "length does not match list");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 inline JavaAssertions::OptionList*
a61af66fc99e Initial load
duke
parents:
diff changeset
144 JavaAssertions::match_class(const char* classname) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 for (OptionList* p = _classes; p != 0; p = p->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (strcmp(p->name(), classname) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 JavaAssertions::OptionList*
a61af66fc99e Initial load
duke
parents:
diff changeset
154 JavaAssertions::match_package(const char* classname) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Search the package list for any items that apply to classname. Each
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // sub-package in classname is checked, from most-specific to least, until one
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // is found.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (_packages == 0) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Find the length of the "most-specific" package in classname. If classname
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // does not include a package, length will be 0 which will match items for the
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // default package (from options "-ea:..." or "-da:...").
a61af66fc99e Initial load
duke
parents:
diff changeset
163 size_t len = strlen(classname);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 for (/* empty */; len > 0 && classname[len] != '/'; --len) /* empty */;
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 assert(len == 0 || classname[len] == '/', "not a package name");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 for (OptionList* p = _packages; p != 0; p = p->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (strncmp(p->name(), classname, len) == 0 && p->name()[len] == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Find the length of the next package, taking care to avoid decrementing
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // past 0 (len is unsigned).
a61af66fc99e Initial load
duke
parents:
diff changeset
176 while (len > 0 && classname[--len] != '/') /* empty */;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } while (len > 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 inline void JavaAssertions::trace(const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
183 const char* typefound, const char* namefound, bool enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (TraceJavaAssertions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 tty->print_cr("JavaAssertions: search for %s found %s %s=%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
186 name, typefound, namefound[0] != '\0' ? namefound : "'default'", enabled);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 bool JavaAssertions::enabled(const char* classname, bool systemClass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 assert(classname != 0, "must have a classname");
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // This will be slow if the number of assertion options on the command line is
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // large--it traverses two lists, one of them multiple times. Could use a
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // single n-ary tree instead of lists if someone ever notices.
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // First check options that apply to classes. If we find a match we're done.
a61af66fc99e Initial load
duke
parents:
diff changeset
198 OptionList* p;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (p = match_class(classname)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 trace(classname, "class", p->name(), p->enabled());
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return p->enabled();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // Now check packages, from most specific to least.
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (p = match_package(classname)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 trace(classname, "package", p->name(), p->enabled());
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return p->enabled();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // No match. Return the default status.
a61af66fc99e Initial load
duke
parents:
diff changeset
211 bool result = systemClass ? systemClassDefault() : userClassDefault();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 trace(classname, systemClass ? "system" : "user", "default", result);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }