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