Tue, 20 Jul 2010 08:41:42 -0700
6964170: Verifier crashes
Summary: Check if klassOop != NULL rather than klass_part != NULL
Reviewed-by: kamg, never
duke@435 | 1 | /* |
trims@1907 | 2 | * Copyright (c) 2000, 2005, 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 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_javaAssertions.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | bool JavaAssertions::_userDefault = false; |
duke@435 | 29 | bool JavaAssertions::_sysDefault = false; |
duke@435 | 30 | JavaAssertions::OptionList* JavaAssertions::_classes = 0; |
duke@435 | 31 | JavaAssertions::OptionList* JavaAssertions::_packages = 0; |
duke@435 | 32 | |
duke@435 | 33 | JavaAssertions::OptionList::OptionList(const char* name, bool enabled, |
duke@435 | 34 | OptionList* next) { |
duke@435 | 35 | assert(name != 0, "need a name"); |
duke@435 | 36 | _name = name; |
duke@435 | 37 | _enabled = enabled; |
duke@435 | 38 | _next = next; |
duke@435 | 39 | } |
duke@435 | 40 | |
duke@435 | 41 | int JavaAssertions::OptionList::count(OptionList* p) { |
duke@435 | 42 | int rc; |
duke@435 | 43 | for (rc = 0; p != 0; p = p->next(), ++rc) /* empty */; |
duke@435 | 44 | return rc; |
duke@435 | 45 | } |
duke@435 | 46 | |
duke@435 | 47 | void JavaAssertions::addOption(const char* name, bool enable) { |
duke@435 | 48 | assert(name != 0, "must have a name"); |
duke@435 | 49 | |
duke@435 | 50 | // Copy the name. The storage needs to exist for the the lifetime of the vm; |
duke@435 | 51 | // it is never freed, so will be leaked (along with other option strings - |
duke@435 | 52 | // e.g., bootclasspath) if a process creates/destroys multiple VMs. |
duke@435 | 53 | int len = (int)strlen(name); |
duke@435 | 54 | char *name_copy = NEW_C_HEAP_ARRAY(char, len + 1); |
duke@435 | 55 | strcpy(name_copy, name); |
duke@435 | 56 | |
duke@435 | 57 | // Figure out which list the new item should go on. Names that end in "..." |
duke@435 | 58 | // go on the package tree list. |
duke@435 | 59 | OptionList** head = &_classes; |
duke@435 | 60 | if (len >= 3 && strcmp(name_copy + len - 3, "...") == 0) { |
duke@435 | 61 | // Delete the "...". |
duke@435 | 62 | len -= 3; |
duke@435 | 63 | name_copy[len] = '\0'; |
duke@435 | 64 | head = &_packages; |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | // Convert class/package names to internal format. Will have to convert back |
duke@435 | 68 | // when copying to java in createJavaAssertionStatusDirectives, but that |
duke@435 | 69 | // should happen only once. Alternative would require that |
duke@435 | 70 | // JVM_DesiredAssertionStatus pass the external_name() to |
duke@435 | 71 | // JavaAssertion::enabled(), but that is done once per loaded class. |
duke@435 | 72 | for (int i = 0; i < len; ++i) { |
duke@435 | 73 | if (name_copy[i] == '.') name_copy[i] = '/'; |
duke@435 | 74 | } |
duke@435 | 75 | |
duke@435 | 76 | if (TraceJavaAssertions) { |
duke@435 | 77 | tty->print_cr("JavaAssertions: adding %s %s=%d", |
duke@435 | 78 | head == &_classes ? "class" : "package", |
duke@435 | 79 | name_copy[0] != '\0' ? name_copy : "'default'", |
duke@435 | 80 | enable); |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | // Prepend a new item to the list. Items added later take precedence, so |
duke@435 | 84 | // prepending allows us to stop searching the list after the first match. |
duke@435 | 85 | *head = new OptionList(name_copy, enable, *head); |
duke@435 | 86 | } |
duke@435 | 87 | |
duke@435 | 88 | oop JavaAssertions::createAssertionStatusDirectives(TRAPS) { |
duke@435 | 89 | symbolHandle asd_sym = vmSymbolHandles::java_lang_AssertionStatusDirectives(); |
duke@435 | 90 | klassOop k = SystemDictionary::resolve_or_fail(asd_sym, true, CHECK_NULL); |
duke@435 | 91 | instanceKlassHandle asd_klass (THREAD, k); |
duke@435 | 92 | asd_klass->initialize(CHECK_NULL); |
duke@435 | 93 | Handle h = asd_klass->allocate_instance_handle(CHECK_NULL); |
duke@435 | 94 | |
duke@435 | 95 | int len; |
duke@435 | 96 | typeArrayOop t; |
duke@435 | 97 | len = OptionList::count(_packages); |
never@1577 | 98 | objArrayOop pn = oopFactory::new_objArray(SystemDictionary::String_klass(), len, CHECK_NULL); |
duke@435 | 99 | objArrayHandle pkgNames (THREAD, pn); |
duke@435 | 100 | t = oopFactory::new_typeArray(T_BOOLEAN, len, CHECK_NULL); |
duke@435 | 101 | typeArrayHandle pkgEnabled(THREAD, t); |
duke@435 | 102 | fillJavaArrays(_packages, len, pkgNames, pkgEnabled, CHECK_NULL); |
duke@435 | 103 | |
duke@435 | 104 | len = OptionList::count(_classes); |
never@1577 | 105 | objArrayOop cn = oopFactory::new_objArray(SystemDictionary::String_klass(), len, CHECK_NULL); |
duke@435 | 106 | objArrayHandle classNames (THREAD, cn); |
duke@435 | 107 | t = oopFactory::new_typeArray(T_BOOLEAN, len, CHECK_NULL); |
duke@435 | 108 | typeArrayHandle classEnabled(THREAD, t); |
duke@435 | 109 | fillJavaArrays(_classes, len, classNames, classEnabled, CHECK_NULL); |
duke@435 | 110 | |
duke@435 | 111 | java_lang_AssertionStatusDirectives::set_packages(h(), pkgNames()); |
duke@435 | 112 | java_lang_AssertionStatusDirectives::set_packageEnabled(h(), pkgEnabled()); |
duke@435 | 113 | java_lang_AssertionStatusDirectives::set_classes(h(), classNames()); |
duke@435 | 114 | java_lang_AssertionStatusDirectives::set_classEnabled(h(), classEnabled()); |
duke@435 | 115 | java_lang_AssertionStatusDirectives::set_deflt(h(), userClassDefault()); |
duke@435 | 116 | return h(); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | void JavaAssertions::fillJavaArrays(const OptionList* p, int len, |
duke@435 | 120 | objArrayHandle names, typeArrayHandle enabled, TRAPS) { |
duke@435 | 121 | // Fill in the parallel names and enabled (boolean) arrays. Start at the end |
duke@435 | 122 | // of the array and work backwards, so the order of items in the arrays |
duke@435 | 123 | // matches the order on the command line (the list is in reverse order, since |
duke@435 | 124 | // it was created by prepending successive items from the command line). |
duke@435 | 125 | int index; |
duke@435 | 126 | for (index = len - 1; p != 0; p = p->next(), --index) { |
duke@435 | 127 | assert(index >= 0, "length does not match list"); |
duke@435 | 128 | Handle s = java_lang_String::create_from_str(p->name(), CHECK); |
duke@435 | 129 | s = java_lang_String::char_converter(s, '/', '.', CHECK); |
duke@435 | 130 | names->obj_at_put(index, s()); |
duke@435 | 131 | enabled->bool_at_put(index, p->enabled()); |
duke@435 | 132 | } |
duke@435 | 133 | assert(index == -1, "length does not match list"); |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | inline JavaAssertions::OptionList* |
duke@435 | 137 | JavaAssertions::match_class(const char* classname) { |
duke@435 | 138 | for (OptionList* p = _classes; p != 0; p = p->next()) { |
duke@435 | 139 | if (strcmp(p->name(), classname) == 0) { |
duke@435 | 140 | return p; |
duke@435 | 141 | } |
duke@435 | 142 | } |
duke@435 | 143 | return 0; |
duke@435 | 144 | } |
duke@435 | 145 | |
duke@435 | 146 | JavaAssertions::OptionList* |
duke@435 | 147 | JavaAssertions::match_package(const char* classname) { |
duke@435 | 148 | // Search the package list for any items that apply to classname. Each |
duke@435 | 149 | // sub-package in classname is checked, from most-specific to least, until one |
duke@435 | 150 | // is found. |
duke@435 | 151 | if (_packages == 0) return 0; |
duke@435 | 152 | |
duke@435 | 153 | // Find the length of the "most-specific" package in classname. If classname |
duke@435 | 154 | // does not include a package, length will be 0 which will match items for the |
duke@435 | 155 | // default package (from options "-ea:..." or "-da:..."). |
duke@435 | 156 | size_t len = strlen(classname); |
duke@435 | 157 | for (/* empty */; len > 0 && classname[len] != '/'; --len) /* empty */; |
duke@435 | 158 | |
duke@435 | 159 | do { |
duke@435 | 160 | assert(len == 0 || classname[len] == '/', "not a package name"); |
duke@435 | 161 | for (OptionList* p = _packages; p != 0; p = p->next()) { |
duke@435 | 162 | if (strncmp(p->name(), classname, len) == 0 && p->name()[len] == '\0') { |
duke@435 | 163 | return p; |
duke@435 | 164 | } |
duke@435 | 165 | } |
duke@435 | 166 | |
duke@435 | 167 | // Find the length of the next package, taking care to avoid decrementing |
duke@435 | 168 | // past 0 (len is unsigned). |
duke@435 | 169 | while (len > 0 && classname[--len] != '/') /* empty */; |
duke@435 | 170 | } while (len > 0); |
duke@435 | 171 | |
duke@435 | 172 | return 0; |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | inline void JavaAssertions::trace(const char* name, |
duke@435 | 176 | const char* typefound, const char* namefound, bool enabled) { |
duke@435 | 177 | if (TraceJavaAssertions) { |
duke@435 | 178 | tty->print_cr("JavaAssertions: search for %s found %s %s=%d", |
duke@435 | 179 | name, typefound, namefound[0] != '\0' ? namefound : "'default'", enabled); |
duke@435 | 180 | } |
duke@435 | 181 | } |
duke@435 | 182 | |
duke@435 | 183 | bool JavaAssertions::enabled(const char* classname, bool systemClass) { |
duke@435 | 184 | assert(classname != 0, "must have a classname"); |
duke@435 | 185 | |
duke@435 | 186 | // This will be slow if the number of assertion options on the command line is |
duke@435 | 187 | // large--it traverses two lists, one of them multiple times. Could use a |
duke@435 | 188 | // single n-ary tree instead of lists if someone ever notices. |
duke@435 | 189 | |
duke@435 | 190 | // First check options that apply to classes. If we find a match we're done. |
duke@435 | 191 | OptionList* p; |
duke@435 | 192 | if (p = match_class(classname)) { |
duke@435 | 193 | trace(classname, "class", p->name(), p->enabled()); |
duke@435 | 194 | return p->enabled(); |
duke@435 | 195 | } |
duke@435 | 196 | |
duke@435 | 197 | // Now check packages, from most specific to least. |
duke@435 | 198 | if (p = match_package(classname)) { |
duke@435 | 199 | trace(classname, "package", p->name(), p->enabled()); |
duke@435 | 200 | return p->enabled(); |
duke@435 | 201 | } |
duke@435 | 202 | |
duke@435 | 203 | // No match. Return the default status. |
duke@435 | 204 | bool result = systemClass ? systemClassDefault() : userClassDefault(); |
duke@435 | 205 | trace(classname, systemClass ? "system" : "user", "default", result); |
duke@435 | 206 | return result; |
duke@435 | 207 | } |