| File: | jdk/src/hotspot/share/utilities/globalDefinitions.hpp |
| Warning: | line 1200, column 3 Undefined or garbage value returned to caller |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | ||||
| 2 | * Copyright (c) 1997, 2021, 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 "cds/cppVtables.hpp" | ||||
| 27 | #include "cds/metaspaceShared.hpp" | ||||
| 28 | #include "classfile/classLoaderDataGraph.hpp" | ||||
| 29 | #include "classfile/metadataOnStackMark.hpp" | ||||
| 30 | #include "classfile/symbolTable.hpp" | ||||
| 31 | #include "classfile/systemDictionary.hpp" | ||||
| 32 | #include "classfile/vmClasses.hpp" | ||||
| 33 | #include "code/codeCache.hpp" | ||||
| 34 | #include "code/debugInfoRec.hpp" | ||||
| 35 | #include "compiler/compilationPolicy.hpp" | ||||
| 36 | #include "gc/shared/collectedHeap.inline.hpp" | ||||
| 37 | #include "interpreter/bytecodeStream.hpp" | ||||
| 38 | #include "interpreter/bytecodeTracer.hpp" | ||||
| 39 | #include "interpreter/bytecodes.hpp" | ||||
| 40 | #include "interpreter/interpreter.hpp" | ||||
| 41 | #include "interpreter/oopMapCache.hpp" | ||||
| 42 | #include "logging/log.hpp" | ||||
| 43 | #include "logging/logTag.hpp" | ||||
| 44 | #include "logging/logStream.hpp" | ||||
| 45 | #include "memory/allocation.inline.hpp" | ||||
| 46 | #include "memory/metadataFactory.hpp" | ||||
| 47 | #include "memory/metaspaceClosure.hpp" | ||||
| 48 | #include "memory/oopFactory.hpp" | ||||
| 49 | #include "memory/resourceArea.hpp" | ||||
| 50 | #include "memory/universe.hpp" | ||||
| 51 | #include "oops/constMethod.hpp" | ||||
| 52 | #include "oops/constantPool.hpp" | ||||
| 53 | #include "oops/klass.inline.hpp" | ||||
| 54 | #include "oops/method.inline.hpp" | ||||
| 55 | #include "oops/methodData.hpp" | ||||
| 56 | #include "oops/objArrayKlass.hpp" | ||||
| 57 | #include "oops/objArrayOop.inline.hpp" | ||||
| 58 | #include "oops/oop.inline.hpp" | ||||
| 59 | #include "oops/symbol.hpp" | ||||
| 60 | #include "prims/jvmtiExport.hpp" | ||||
| 61 | #include "prims/methodHandles.hpp" | ||||
| 62 | #include "runtime/arguments.hpp" | ||||
| 63 | #include "runtime/atomic.hpp" | ||||
| 64 | #include "runtime/frame.inline.hpp" | ||||
| 65 | #include "runtime/handles.inline.hpp" | ||||
| 66 | #include "runtime/init.hpp" | ||||
| 67 | #include "runtime/orderAccess.hpp" | ||||
| 68 | #include "runtime/relocator.hpp" | ||||
| 69 | #include "runtime/safepointVerifiers.hpp" | ||||
| 70 | #include "runtime/sharedRuntime.hpp" | ||||
| 71 | #include "runtime/signature.hpp" | ||||
| 72 | #include "runtime/vm_version.hpp" | ||||
| 73 | #include "services/memTracker.hpp" | ||||
| 74 | #include "utilities/align.hpp" | ||||
| 75 | #include "utilities/quickSort.hpp" | ||||
| 76 | #include "utilities/vmError.hpp" | ||||
| 77 | #include "utilities/xmlstream.hpp" | ||||
| 78 | |||||
| 79 | // Implementation of Method | ||||
| 80 | |||||
| 81 | Method* Method::allocate(ClassLoaderData* loader_data, | ||||
| 82 | int byte_code_size, | ||||
| 83 | AccessFlags access_flags, | ||||
| 84 | InlineTableSizes* sizes, | ||||
| 85 | ConstMethod::MethodType method_type, | ||||
| 86 | TRAPSJavaThread* __the_thread__) { | ||||
| 87 | assert(!access_flags.is_native() || byte_code_size == 0,do { if (!(!access_flags.is_native() || byte_code_size == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 88, "assert(" "!access_flags.is_native() || byte_code_size == 0" ") failed", "native methods should not contain byte codes"); ::breakpoint(); } } while (0) | ||||
| 88 | "native methods should not contain byte codes")do { if (!(!access_flags.is_native() || byte_code_size == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 88, "assert(" "!access_flags.is_native() || byte_code_size == 0" ") failed", "native methods should not contain byte codes"); ::breakpoint(); } } while (0); | ||||
| 89 | ConstMethod* cm = ConstMethod::allocate(loader_data, | ||||
| 90 | byte_code_size, | ||||
| 91 | sizes, | ||||
| 92 | method_type, | ||||
| 93 | CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); | ||||
| 94 | int size = Method::size(access_flags.is_native()); | ||||
| 95 | return new (loader_data, size, MetaspaceObj::MethodType, THREAD__the_thread__) Method(cm, access_flags); | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | Method::Method(ConstMethod* xconst, AccessFlags access_flags) { | ||||
| 99 | NoSafepointVerifier no_safepoint; | ||||
| 100 | set_constMethod(xconst); | ||||
| 101 | set_access_flags(access_flags); | ||||
| 102 | set_intrinsic_id(vmIntrinsics::_none); | ||||
| 103 | set_force_inline(false); | ||||
| 104 | set_hidden(false); | ||||
| 105 | set_dont_inline(false); | ||||
| 106 | set_has_injected_profile(false); | ||||
| 107 | set_method_data(NULL__null); | ||||
| 108 | clear_method_counters(); | ||||
| 109 | set_vtable_index(Method::garbage_vtable_index); | ||||
| 110 | |||||
| 111 | // Fix and bury in Method* | ||||
| 112 | set_interpreter_entry(NULL__null); // sets i2i entry and from_int | ||||
| 113 | set_adapter_entry(NULL__null); | ||||
| 114 | Method::clear_code(); // from_c/from_i get set to c2i/i2i | ||||
| 115 | |||||
| 116 | if (access_flags.is_native()) { | ||||
| 117 | clear_native_function(); | ||||
| 118 | set_signature_handler(NULL__null); | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | NOT_PRODUCT(set_compiled_invocation_count(0);)set_compiled_invocation_count(0); | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | // Release Method*. The nmethod will be gone when we get here because | ||||
| 125 | // we've walked the code cache. | ||||
| 126 | void Method::deallocate_contents(ClassLoaderData* loader_data) { | ||||
| 127 | MetadataFactory::free_metadata(loader_data, constMethod()); | ||||
| 128 | set_constMethod(NULL__null); | ||||
| 129 | MetadataFactory::free_metadata(loader_data, method_data()); | ||||
| 130 | set_method_data(NULL__null); | ||||
| 131 | MetadataFactory::free_metadata(loader_data, method_counters()); | ||||
| 132 | clear_method_counters(); | ||||
| 133 | // The nmethod will be gone when we get here. | ||||
| 134 | if (code() != NULL__null) _code = NULL__null; | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | void Method::release_C_heap_structures() { | ||||
| 138 | if (method_data()) { | ||||
| 139 | #if INCLUDE_JVMCI1 | ||||
| 140 | FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address()); | ||||
| 141 | #endif | ||||
| 142 | // Destroy MethodData | ||||
| 143 | method_data()->~MethodData(); | ||||
| 144 | } | ||||
| 145 | } | ||||
| 146 | |||||
| 147 | address Method::get_i2c_entry() { | ||||
| 148 | assert(adapter() != NULL, "must have")do { if (!(adapter() != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 148, "assert(" "adapter() != __null" ") failed", "must have" ); ::breakpoint(); } } while (0); | ||||
| 149 | return adapter()->get_i2c_entry(); | ||||
| 150 | } | ||||
| 151 | |||||
| 152 | address Method::get_c2i_entry() { | ||||
| 153 | assert(adapter() != NULL, "must have")do { if (!(adapter() != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 153, "assert(" "adapter() != __null" ") failed", "must have" ); ::breakpoint(); } } while (0); | ||||
| 154 | return adapter()->get_c2i_entry(); | ||||
| 155 | } | ||||
| 156 | |||||
| 157 | address Method::get_c2i_unverified_entry() { | ||||
| 158 | assert(adapter() != NULL, "must have")do { if (!(adapter() != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 158, "assert(" "adapter() != __null" ") failed", "must have" ); ::breakpoint(); } } while (0); | ||||
| 159 | return adapter()->get_c2i_unverified_entry(); | ||||
| 160 | } | ||||
| 161 | |||||
| 162 | address Method::get_c2i_no_clinit_check_entry() { | ||||
| 163 | assert(VM_Version::supports_fast_class_init_checks(), "")do { if (!(VM_Version::supports_fast_class_init_checks())) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 163, "assert(" "VM_Version::supports_fast_class_init_checks()" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 164 | assert(adapter() != NULL, "must have")do { if (!(adapter() != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 164, "assert(" "adapter() != __null" ") failed", "must have" ); ::breakpoint(); } } while (0); | ||||
| 165 | return adapter()->get_c2i_no_clinit_check_entry(); | ||||
| 166 | } | ||||
| 167 | |||||
| 168 | char* Method::name_and_sig_as_C_string() const { | ||||
| 169 | return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature()); | ||||
| 170 | } | ||||
| 171 | |||||
| 172 | char* Method::name_and_sig_as_C_string(char* buf, int size) const { | ||||
| 173 | return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size); | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) { | ||||
| 177 | const char* klass_name = klass->external_name(); | ||||
| 178 | int klass_name_len = (int)strlen(klass_name); | ||||
| 179 | int method_name_len = method_name->utf8_length(); | ||||
| 180 | int len = klass_name_len + 1 + method_name_len + signature->utf8_length(); | ||||
| 181 | char* dest = NEW_RESOURCE_ARRAY(char, len + 1)(char*) resource_allocate_bytes((len + 1) * sizeof(char)); | ||||
| 182 | strcpy(dest, klass_name); | ||||
| 183 | dest[klass_name_len] = '.'; | ||||
| 184 | strcpy(&dest[klass_name_len + 1], method_name->as_C_string()); | ||||
| 185 | strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string()); | ||||
| 186 | dest[len] = 0; | ||||
| 187 | return dest; | ||||
| 188 | } | ||||
| 189 | |||||
| 190 | char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) { | ||||
| 191 | Symbol* klass_name = klass->name(); | ||||
| 192 | klass_name->as_klass_external_name(buf, size); | ||||
| 193 | int len = (int)strlen(buf); | ||||
| 194 | |||||
| 195 | if (len < size - 1) { | ||||
| 196 | buf[len++] = '.'; | ||||
| 197 | |||||
| 198 | method_name->as_C_string(&(buf[len]), size - len); | ||||
| 199 | len = (int)strlen(buf); | ||||
| 200 | |||||
| 201 | signature->as_C_string(&(buf[len]), size - len); | ||||
| 202 | } | ||||
| 203 | |||||
| 204 | return buf; | ||||
| 205 | } | ||||
| 206 | |||||
| 207 | const char* Method::external_name() const { | ||||
| 208 | return external_name(constants()->pool_holder(), name(), signature()); | ||||
| 209 | } | ||||
| 210 | |||||
| 211 | void Method::print_external_name(outputStream *os) const { | ||||
| 212 | print_external_name(os, constants()->pool_holder(), name(), signature()); | ||||
| 213 | } | ||||
| 214 | |||||
| 215 | const char* Method::external_name(Klass* klass, Symbol* method_name, Symbol* signature) { | ||||
| 216 | stringStream ss; | ||||
| 217 | print_external_name(&ss, klass, method_name, signature); | ||||
| 218 | return ss.as_string(); | ||||
| 219 | } | ||||
| 220 | |||||
| 221 | void Method::print_external_name(outputStream *os, Klass* klass, Symbol* method_name, Symbol* signature) { | ||||
| 222 | signature->print_as_signature_external_return_type(os); | ||||
| 223 | os->print(" %s.%s(", klass->external_name(), method_name->as_C_string()); | ||||
| 224 | signature->print_as_signature_external_parameters(os); | ||||
| 225 | os->print(")"); | ||||
| 226 | } | ||||
| 227 | |||||
| 228 | int Method::fast_exception_handler_bci_for(const methodHandle& mh, Klass* ex_klass, int throw_bci, TRAPSJavaThread* __the_thread__) { | ||||
| 229 | if (log_is_enabled(Debug, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) { | ||||
| 230 | ResourceMark rm(THREAD__the_thread__); | ||||
| 231 | log_debug(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("Looking for catch handler for exception of type \"%s\" in method \"%s\"", | ||||
| 232 | ex_klass == NULL__null ? "NULL" : ex_klass->external_name(), mh->name()->as_C_string()); | ||||
| 233 | } | ||||
| 234 | // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) | ||||
| 235 | // access exception table | ||||
| 236 | ExceptionTable table(mh()); | ||||
| 237 | int length = table.length(); | ||||
| 238 | // iterate through all entries sequentially | ||||
| 239 | constantPoolHandle pool(THREAD__the_thread__, mh->constants()); | ||||
| 240 | for (int i = 0; i < length; i ++) { | ||||
| 241 | //reacquire the table in case a GC happened | ||||
| 242 | ExceptionTable table(mh()); | ||||
| 243 | int beg_bci = table.start_pc(i); | ||||
| 244 | int end_bci = table.end_pc(i); | ||||
| 245 | assert(beg_bci <= end_bci, "inconsistent exception table")do { if (!(beg_bci <= end_bci)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 245, "assert(" "beg_bci <= end_bci" ") failed", "inconsistent exception table" ); ::breakpoint(); } } while (0); | ||||
| 246 | log_debug(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>(" - checking exception table entry for BCI %d to %d", | ||||
| 247 | beg_bci, end_bci); | ||||
| 248 | |||||
| 249 | if (beg_bci <= throw_bci && throw_bci < end_bci) { | ||||
| 250 | // exception handler bci range covers throw_bci => investigate further | ||||
| 251 | log_debug(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>(" - entry covers throw point BCI %d", throw_bci); | ||||
| 252 | |||||
| 253 | int handler_bci = table.handler_pc(i); | ||||
| 254 | int klass_index = table.catch_type_index(i); | ||||
| 255 | if (klass_index == 0) { | ||||
| 256 | if (log_is_enabled(Info, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) { | ||||
| 257 | ResourceMark rm(THREAD__the_thread__); | ||||
| 258 | log_info(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("Found catch-all handler for exception of type \"%s\" in method \"%s\" at BCI: %d", | ||||
| 259 | ex_klass == NULL__null ? "NULL" : ex_klass->external_name(), mh->name()->as_C_string(), handler_bci); | ||||
| 260 | } | ||||
| 261 | return handler_bci; | ||||
| 262 | } else if (ex_klass == NULL__null) { | ||||
| 263 | // Is this even possible? | ||||
| 264 | if (log_is_enabled(Info, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) { | ||||
| 265 | ResourceMark rm(THREAD__the_thread__); | ||||
| 266 | log_info(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("NULL exception class is implicitly caught by handler in method \"%s\" at BCI: %d", | ||||
| 267 | mh()->name()->as_C_string(), handler_bci); | ||||
| 268 | } | ||||
| 269 | return handler_bci; | ||||
| 270 | } else { | ||||
| 271 | if (log_is_enabled(Debug, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) { | ||||
| 272 | ResourceMark rm(THREAD__the_thread__); | ||||
| 273 | log_debug(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>(" - resolving catch type \"%s\"", | ||||
| 274 | pool->klass_name_at(klass_index)->as_C_string()); | ||||
| 275 | } | ||||
| 276 | // we know the exception class => get the constraint class | ||||
| 277 | // this may require loading of the constraint class; if verification | ||||
| 278 | // fails or some other exception occurs, return handler_bci | ||||
| 279 | Klass* k = pool->klass_at(klass_index, THREAD__the_thread__); | ||||
| 280 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | ||||
| 281 | if (log_is_enabled(Debug, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) { | ||||
| 282 | ResourceMark rm(THREAD__the_thread__); | ||||
| 283 | log_debug(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>(" - exception \"%s\" occurred resolving catch type", | ||||
| 284 | PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())->klass()->external_name()); | ||||
| 285 | } | ||||
| 286 | return handler_bci; | ||||
| 287 | } | ||||
| 288 | assert(k != NULL, "klass not loaded")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 288, "assert(" "k != __null" ") failed", "klass not loaded" ); ::breakpoint(); } } while (0); | ||||
| 289 | if (ex_klass->is_subtype_of(k)) { | ||||
| 290 | if (log_is_enabled(Info, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) { | ||||
| 291 | ResourceMark rm(THREAD__the_thread__); | ||||
| 292 | log_info(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("Found matching handler for exception of type \"%s\" in method \"%s\" at BCI: %d", | ||||
| 293 | ex_klass == NULL__null ? "NULL" : ex_klass->external_name(), mh->name()->as_C_string(), handler_bci); | ||||
| 294 | } | ||||
| 295 | return handler_bci; | ||||
| 296 | } | ||||
| 297 | } | ||||
| 298 | } | ||||
| 299 | } | ||||
| 300 | |||||
| 301 | if (log_is_enabled(Debug, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) { | ||||
| 302 | ResourceMark rm(THREAD__the_thread__); | ||||
| 303 | log_debug(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("No catch handler found for exception of type \"%s\" in method \"%s\"", | ||||
| 304 | ex_klass->external_name(), mh->name()->as_C_string()); | ||||
| 305 | } | ||||
| 306 | |||||
| 307 | return -1; | ||||
| 308 | } | ||||
| 309 | |||||
| 310 | void Method::mask_for(int bci, InterpreterOopMap* mask) { | ||||
| 311 | methodHandle h_this(Thread::current(), this); | ||||
| 312 | // Only GC uses the OopMapCache during thread stack root scanning | ||||
| 313 | // any other uses generate an oopmap but do not save it in the cache. | ||||
| 314 | if (Universe::heap()->is_gc_active()) { | ||||
| 315 | method_holder()->mask_for(h_this, bci, mask); | ||||
| 316 | } else { | ||||
| 317 | OopMapCache::compute_one_oop_map(h_this, bci, mask); | ||||
| 318 | } | ||||
| 319 | return; | ||||
| 320 | } | ||||
| 321 | |||||
| 322 | |||||
| 323 | int Method::bci_from(address bcp) const { | ||||
| 324 | if (is_native() && bcp == 0) { | ||||
| 325 | return 0; | ||||
| 326 | } | ||||
| 327 | // Do not have a ResourceMark here because AsyncGetCallTrace stack walking code | ||||
| 328 | // may call this after interrupting a nested ResourceMark. | ||||
| 329 | assert(is_native() && bcp == code_base() || contains(bcp) || VMError::is_error_reported(),do { if (!(is_native() && bcp == code_base() || contains (bcp) || VMError::is_error_reported())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 330, "assert(" "is_native() && bcp == code_base() || contains(bcp) || VMError::is_error_reported()" ") failed", "bcp doesn't belong to this method. bcp: " "0x%016" "l" "x", p2i(bcp)); ::breakpoint(); } } while (0) | ||||
| 330 | "bcp doesn't belong to this method. bcp: " INTPTR_FORMAT, p2i(bcp))do { if (!(is_native() && bcp == code_base() || contains (bcp) || VMError::is_error_reported())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 330, "assert(" "is_native() && bcp == code_base() || contains(bcp) || VMError::is_error_reported()" ") failed", "bcp doesn't belong to this method. bcp: " "0x%016" "l" "x", p2i(bcp)); ::breakpoint(); } } while (0); | ||||
| 331 | |||||
| 332 | return bcp - code_base(); | ||||
| 333 | } | ||||
| 334 | |||||
| 335 | |||||
| 336 | int Method::validate_bci(int bci) const { | ||||
| 337 | return (bci == 0 || bci < code_size()) ? bci : -1; | ||||
| 338 | } | ||||
| 339 | |||||
| 340 | // Return bci if it appears to be a valid bcp | ||||
| 341 | // Return -1 otherwise. | ||||
| 342 | // Used by profiling code, when invalid data is a possibility. | ||||
| 343 | // The caller is responsible for validating the Method* itself. | ||||
| 344 | int Method::validate_bci_from_bcp(address bcp) const { | ||||
| 345 | // keep bci as -1 if not a valid bci | ||||
| 346 | int bci = -1; | ||||
| 347 | if (bcp == 0 || bcp == code_base()) { | ||||
| 348 | // code_size() may return 0 and we allow 0 here | ||||
| 349 | // the method may be native | ||||
| 350 | bci = 0; | ||||
| 351 | } else if (contains(bcp)) { | ||||
| 352 | bci = bcp - code_base(); | ||||
| 353 | } | ||||
| 354 | // Assert that if we have dodged any asserts, bci is negative. | ||||
| 355 | assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0")do { if (!(bci == -1 || bci == bci_from(bcp_from(bci)))) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 355, "assert(" "bci == -1 || bci == bci_from(bcp_from(bci))" ") failed", "sane bci if >=0"); ::breakpoint(); } } while (0); | ||||
| 356 | return bci; | ||||
| 357 | } | ||||
| 358 | |||||
| 359 | address Method::bcp_from(int bci) const { | ||||
| 360 | assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()),do { if (!((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 361, "assert(" "(is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size())" ") failed", "illegal bci: %d for %s method", bci, is_native( ) ? "native" : "non-native"); ::breakpoint(); } } while (0) | ||||
| 361 | "illegal bci: %d for %s method", bci, is_native() ? "native" : "non-native")do { if (!((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 361, "assert(" "(is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size())" ") failed", "illegal bci: %d for %s method", bci, is_native( ) ? "native" : "non-native"); ::breakpoint(); } } while (0); | ||||
| 362 | address bcp = code_base() + bci; | ||||
| 363 | assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method")do { if (!(is_native() && bcp == code_base() || contains (bcp))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 363, "assert(" "is_native() && bcp == code_base() || contains(bcp)" ") failed", "bcp doesn't belong to this method"); ::breakpoint (); } } while (0); | ||||
| 364 | return bcp; | ||||
| 365 | } | ||||
| 366 | |||||
| 367 | address Method::bcp_from(address bcp) const { | ||||
| 368 | if (is_native() && bcp == NULL__null) { | ||||
| 369 | return code_base(); | ||||
| 370 | } else { | ||||
| 371 | return bcp; | ||||
| 372 | } | ||||
| 373 | } | ||||
| 374 | |||||
| 375 | int Method::size(bool is_native) { | ||||
| 376 | // If native, then include pointers for native_function and signature_handler | ||||
| 377 | int extra_bytes = (is_native) ? 2*sizeof(address*) : 0; | ||||
| 378 | int extra_words = align_up(extra_bytes, BytesPerWord) / BytesPerWord; | ||||
| 379 | return align_metadata_size(header_size() + extra_words); | ||||
| 380 | } | ||||
| 381 | |||||
| 382 | Symbol* Method::klass_name() const { | ||||
| 383 | return method_holder()->name(); | ||||
| 384 | } | ||||
| 385 | |||||
| 386 | void Method::metaspace_pointers_do(MetaspaceClosure* it) { | ||||
| 387 | log_trace(cds)(!(LogImpl<(LogTag::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Iter(Method): %p", this); | ||||
| 388 | |||||
| 389 | if (!method_holder()->is_rewritten()) { | ||||
| 390 | it->push(&_constMethod, MetaspaceClosure::_writable); | ||||
| 391 | } else { | ||||
| 392 | it->push(&_constMethod); | ||||
| 393 | } | ||||
| 394 | it->push(&_method_data); | ||||
| 395 | it->push(&_method_counters); | ||||
| 396 | } | ||||
| 397 | |||||
| 398 | // Attempt to return method to original state. Clear any pointers | ||||
| 399 | // (to objects outside the shared spaces). We won't be able to predict | ||||
| 400 | // where they should point in a new JVM. Further initialize some | ||||
| 401 | // entries now in order allow them to be write protected later. | ||||
| 402 | |||||
| 403 | void Method::remove_unshareable_info() { | ||||
| 404 | unlink_method(); | ||||
| 405 | JFR_ONLY(REMOVE_METHOD_ID(this);)JfrTraceId::remove(this);; | ||||
| 406 | } | ||||
| 407 | |||||
| 408 | void Method::set_vtable_index(int index) { | ||||
| 409 | if (is_shared() && !MetaspaceShared::remapped_readwrite() && method_holder()->verified_at_dump_time()) { | ||||
| 410 | // At runtime initialize_vtable is rerun as part of link_class_impl() | ||||
| 411 | // for a shared class loaded by the non-boot loader to obtain the loader | ||||
| 412 | // constraints based on the runtime classloaders' context. | ||||
| 413 | return; // don't write into the shared class | ||||
| 414 | } else { | ||||
| 415 | _vtable_index = index; | ||||
| 416 | } | ||||
| 417 | } | ||||
| 418 | |||||
| 419 | void Method::set_itable_index(int index) { | ||||
| 420 | if (is_shared() && !MetaspaceShared::remapped_readwrite() && method_holder()->verified_at_dump_time()) { | ||||
| 421 | // At runtime initialize_itable is rerun as part of link_class_impl() | ||||
| 422 | // for a shared class loaded by the non-boot loader to obtain the loader | ||||
| 423 | // constraints based on the runtime classloaders' context. The dumptime | ||||
| 424 | // itable index should be the same as the runtime index. | ||||
| 425 | assert(_vtable_index == itable_index_max - index,do { if (!(_vtable_index == itable_index_max - index)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 426, "assert(" "_vtable_index == itable_index_max - index" ") failed" , "archived itable index is different from runtime index"); :: breakpoint(); } } while (0) | ||||
| 426 | "archived itable index is different from runtime index")do { if (!(_vtable_index == itable_index_max - index)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 426, "assert(" "_vtable_index == itable_index_max - index" ") failed" , "archived itable index is different from runtime index"); :: breakpoint(); } } while (0); | ||||
| 427 | return; // don’t write into the shared class | ||||
| 428 | } else { | ||||
| 429 | _vtable_index = itable_index_max - index; | ||||
| 430 | } | ||||
| 431 | assert(valid_itable_index(), "")do { if (!(valid_itable_index())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 431, "assert(" "valid_itable_index()" ") failed", ""); ::breakpoint (); } } while (0); | ||||
| 432 | } | ||||
| 433 | |||||
| 434 | // The RegisterNatives call being attempted tried to register with a method that | ||||
| 435 | // is not native. Ask JVM TI what prefixes have been specified. Then check | ||||
| 436 | // to see if the native method is now wrapped with the prefixes. See the | ||||
| 437 | // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details. | ||||
| 438 | static Method* find_prefixed_native(Klass* k, Symbol* name, Symbol* signature, TRAPSJavaThread* __the_thread__) { | ||||
| 439 | #if INCLUDE_JVMTI1 | ||||
| 440 | ResourceMark rm(THREAD__the_thread__); | ||||
| 441 | Method* method; | ||||
| 442 | int name_len = name->utf8_length(); | ||||
| 443 | char* name_str = name->as_utf8(); | ||||
| 444 | int prefix_count; | ||||
| 445 | char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); | ||||
| 446 | for (int i = 0; i < prefix_count; i++) { | ||||
| 447 | char* prefix = prefixes[i]; | ||||
| 448 | int prefix_len = (int)strlen(prefix); | ||||
| 449 | |||||
| 450 | // try adding this prefix to the method name and see if it matches another method name | ||||
| 451 | int trial_len = name_len + prefix_len; | ||||
| 452 | char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1)(char*) resource_allocate_bytes((trial_len + 1) * sizeof(char )); | ||||
| 453 | strcpy(trial_name_str, prefix); | ||||
| 454 | strcat(trial_name_str, name_str); | ||||
| 455 | TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len); | ||||
| 456 | if (trial_name == NULL__null) { | ||||
| 457 | continue; // no such symbol, so this prefix wasn't used, try the next prefix | ||||
| 458 | } | ||||
| 459 | method = k->lookup_method(trial_name, signature); | ||||
| 460 | if (method == NULL__null) { | ||||
| 461 | continue; // signature doesn't match, try the next prefix | ||||
| 462 | } | ||||
| 463 | if (method->is_native()) { | ||||
| 464 | method->set_is_prefixed_native(); | ||||
| 465 | return method; // wahoo, we found a prefixed version of the method, return it | ||||
| 466 | } | ||||
| 467 | // found as non-native, so prefix is good, add it, probably just need more prefixes | ||||
| 468 | name_len = trial_len; | ||||
| 469 | name_str = trial_name_str; | ||||
| 470 | } | ||||
| 471 | #endif // INCLUDE_JVMTI | ||||
| 472 | return NULL__null; // not found | ||||
| 473 | } | ||||
| 474 | |||||
| 475 | bool Method::register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPSJavaThread* __the_thread__) { | ||||
| 476 | Method* method = k->lookup_method(name, signature); | ||||
| 477 | if (method == NULL__null) { | ||||
| 478 | ResourceMark rm(THREAD__the_thread__); | ||||
| 479 | stringStream st; | ||||
| 480 | st.print("Method '"); | ||||
| 481 | print_external_name(&st, k, name, signature); | ||||
| 482 | st.print("' name or signature does not match"); | ||||
| 483 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 483, vmSymbols::java_lang_NoSuchMethodError(), st.as_string ()); return false; }; | ||||
| 484 | } | ||||
| 485 | if (!method->is_native()) { | ||||
| 486 | // trying to register to a non-native method, see if a JVM TI agent has added prefix(es) | ||||
| 487 | method = find_prefixed_native(k, name, signature, THREAD__the_thread__); | ||||
| 488 | if (method == NULL__null) { | ||||
| 489 | ResourceMark rm(THREAD__the_thread__); | ||||
| 490 | stringStream st; | ||||
| 491 | st.print("Method '"); | ||||
| 492 | print_external_name(&st, k, name, signature); | ||||
| 493 | st.print("' is not declared as native"); | ||||
| 494 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 494, vmSymbols::java_lang_NoSuchMethodError(), st.as_string ()); return false; }; | ||||
| 495 | } | ||||
| 496 | } | ||||
| 497 | |||||
| 498 | if (entry != NULL__null) { | ||||
| 499 | method->set_native_function(entry, native_bind_event_is_interesting); | ||||
| 500 | } else { | ||||
| 501 | method->clear_native_function(); | ||||
| 502 | } | ||||
| 503 | if (log_is_enabled(Debug, jni, resolve)(LogImpl<(LogTag::_jni), (LogTag::_resolve), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Debug))) { | ||||
| 504 | ResourceMark rm(THREAD__the_thread__); | ||||
| 505 | log_debug(jni, resolve)(!(LogImpl<(LogTag::_jni), (LogTag::_resolve), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Debug))) ? (void)0 : LogImpl<(LogTag ::_jni), (LogTag::_resolve), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Debug>("[Registering JNI native method %s.%s]", | ||||
| 506 | method->method_holder()->external_name(), | ||||
| 507 | method->name()->as_C_string()); | ||||
| 508 | } | ||||
| 509 | return true; | ||||
| 510 | } | ||||
| 511 | |||||
| 512 | bool Method::was_executed_more_than(int n) { | ||||
| 513 | // Invocation counter is reset when the Method* is compiled. | ||||
| 514 | // If the method has compiled code we therefore assume it has | ||||
| 515 | // be excuted more than n times. | ||||
| 516 | if (is_accessor() || is_empty_method() || (code() != NULL__null)) { | ||||
| 517 | // interpreter doesn't bump invocation counter of trivial methods | ||||
| 518 | // compiler does not bump invocation counter of compiled methods | ||||
| 519 | return true; | ||||
| 520 | } | ||||
| 521 | else if ((method_counters() != NULL__null && | ||||
| 522 | method_counters()->invocation_counter()->carry()) || | ||||
| 523 | (method_data() != NULL__null && | ||||
| 524 | method_data()->invocation_counter()->carry())) { | ||||
| 525 | // The carry bit is set when the counter overflows and causes | ||||
| 526 | // a compilation to occur. We don't know how many times | ||||
| 527 | // the counter has been reset, so we simply assume it has | ||||
| 528 | // been executed more than n times. | ||||
| 529 | return true; | ||||
| 530 | } else { | ||||
| 531 | return invocation_count() > n; | ||||
| 532 | } | ||||
| 533 | } | ||||
| 534 | |||||
| 535 | void Method::print_invocation_count() { | ||||
| 536 | //---< compose+print method return type, klass, name, and signature >--- | ||||
| 537 | if (is_static()) tty->print("static "); | ||||
| 538 | if (is_final()) tty->print("final "); | ||||
| 539 | if (is_synchronized()) tty->print("synchronized "); | ||||
| 540 | if (is_native()) tty->print("native "); | ||||
| 541 | tty->print("%s::", method_holder()->external_name()); | ||||
| 542 | name()->print_symbol_on(tty); | ||||
| 543 | signature()->print_symbol_on(tty); | ||||
| 544 | |||||
| 545 | if (WizardMode) { | ||||
| 546 | // dump the size of the byte codes | ||||
| 547 | tty->print(" {%d}", code_size()); | ||||
| 548 | } | ||||
| 549 | tty->cr(); | ||||
| 550 | |||||
| 551 | // Counting based on signed int counters tends to overflow with | ||||
| 552 | // longer-running workloads on fast machines. The counters under | ||||
| 553 | // consideration here, however, are limited in range by counting | ||||
| 554 | // logic. See InvocationCounter:count_limit for example. | ||||
| 555 | // No "overflow precautions" need to be implemented here. | ||||
| 556 | tty->print_cr (" interpreter_invocation_count: " INT32_FORMAT_W(11)"%" "11" "d", interpreter_invocation_count()); | ||||
| 557 | tty->print_cr (" invocation_counter: " INT32_FORMAT_W(11)"%" "11" "d", invocation_count()); | ||||
| 558 | tty->print_cr (" backedge_counter: " INT32_FORMAT_W(11)"%" "11" "d", backedge_count()); | ||||
| 559 | |||||
| 560 | if (method_data() != NULL__null) { | ||||
| 561 | tty->print_cr (" decompile_count: " UINT32_FORMAT_W(11)"%" "11" "u", method_data()->decompile_count()); | ||||
| 562 | } | ||||
| 563 | |||||
| 564 | #ifndef PRODUCT | ||||
| 565 | if (CountCompiledCalls) { | ||||
| 566 | tty->print_cr (" compiled_invocation_count: " INT64_FORMAT_W(11)"%" "11" "l" "d", compiled_invocation_count()); | ||||
| 567 | } | ||||
| 568 | #endif | ||||
| 569 | } | ||||
| 570 | |||||
| 571 | // Build a MethodData* object to hold information about this method | ||||
| 572 | // collected in the interpreter. | ||||
| 573 | void Method::build_interpreter_method_data(const methodHandle& method, TRAPSJavaThread* __the_thread__) { | ||||
| 574 | // Do not profile the method if metaspace has hit an OOM previously | ||||
| 575 | // allocating profiling data. Callers clear pending exception so don't | ||||
| 576 | // add one here. | ||||
| 577 | if (ClassLoaderDataGraph::has_metaspace_oom()) { | ||||
| 578 | return; | ||||
| 579 | } | ||||
| 580 | |||||
| 581 | // Grab a lock here to prevent multiple | ||||
| 582 | // MethodData*s from being created. | ||||
| 583 | MutexLocker ml(THREAD__the_thread__, MethodData_lock); | ||||
| 584 | if (method->method_data() == NULL__null) { | ||||
| 585 | ClassLoaderData* loader_data = method->method_holder()->class_loader_data(); | ||||
| 586 | MethodData* method_data = MethodData::allocate(loader_data, method, THREAD__the_thread__); | ||||
| 587 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | ||||
| 588 | CompileBroker::log_metaspace_failure(); | ||||
| 589 | ClassLoaderDataGraph::set_metaspace_oom(true); | ||||
| 590 | return; // return the exception (which is cleared) | ||||
| 591 | } | ||||
| 592 | |||||
| 593 | method->set_method_data(method_data); | ||||
| 594 | if (PrintMethodData && (Verbose || WizardMode)) { | ||||
| 595 | ResourceMark rm(THREAD__the_thread__); | ||||
| 596 | tty->print("build_interpreter_method_data for "); | ||||
| 597 | method->print_name(tty); | ||||
| 598 | tty->cr(); | ||||
| 599 | // At the end of the run, the MDO, full of data, will be dumped. | ||||
| 600 | } | ||||
| 601 | } | ||||
| 602 | } | ||||
| 603 | |||||
| 604 | MethodCounters* Method::build_method_counters(Thread* current, Method* m) { | ||||
| 605 | // Do not profile the method if metaspace has hit an OOM previously | ||||
| 606 | if (ClassLoaderDataGraph::has_metaspace_oom()) { | ||||
| 607 | return NULL__null; | ||||
| 608 | } | ||||
| 609 | |||||
| 610 | methodHandle mh(current, m); | ||||
| 611 | MethodCounters* counters; | ||||
| 612 | if (current->is_Java_thread()) { | ||||
| 613 | JavaThread* THREAD__the_thread__ = JavaThread::cast(current); // For exception macros. | ||||
| 614 | // Use the TRAPS version for a JavaThread so it will adjust the GC threshold | ||||
| 615 | // if needed. | ||||
| 616 | counters = MethodCounters::allocate_with_exception(mh, THREAD__the_thread__); | ||||
| 617 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | ||||
| 618 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); | ||||
| 619 | } | ||||
| 620 | } else { | ||||
| 621 | // Call metaspace allocation that doesn't throw exception if the | ||||
| 622 | // current thread isn't a JavaThread, ie. the VMThread. | ||||
| 623 | counters = MethodCounters::allocate_no_exception(mh); | ||||
| 624 | } | ||||
| 625 | |||||
| 626 | if (counters == NULL__null) { | ||||
| 627 | CompileBroker::log_metaspace_failure(); | ||||
| 628 | ClassLoaderDataGraph::set_metaspace_oom(true); | ||||
| 629 | return NULL__null; | ||||
| 630 | } | ||||
| 631 | |||||
| 632 | if (!mh->init_method_counters(counters)) { | ||||
| 633 | MetadataFactory::free_metadata(mh->method_holder()->class_loader_data(), counters); | ||||
| 634 | } | ||||
| 635 | |||||
| 636 | if (LogTouchedMethods) { | ||||
| 637 | mh->log_touched(current); | ||||
| 638 | } | ||||
| 639 | |||||
| 640 | return mh->method_counters(); | ||||
| 641 | } | ||||
| 642 | |||||
| 643 | bool Method::init_method_counters(MethodCounters* counters) { | ||||
| 644 | // Try to install a pointer to MethodCounters, return true on success. | ||||
| 645 | return Atomic::replace_if_null(&_method_counters, counters); | ||||
| 646 | } | ||||
| 647 | |||||
| 648 | int Method::extra_stack_words() { | ||||
| 649 | // not an inline function, to avoid a header dependency on Interpreter | ||||
| 650 | return extra_stack_entries() * Interpreter::stackElementSize; | ||||
| 651 | } | ||||
| 652 | |||||
| 653 | // Derive size of parameters, return type, and fingerprint, | ||||
| 654 | // all in one pass, which is run at load time. | ||||
| 655 | // We need the first two, and might as well grab the third. | ||||
| 656 | void Method::compute_from_signature(Symbol* sig) { | ||||
| 657 | // At this point, since we are scanning the signature, | ||||
| 658 | // we might as well compute the whole fingerprint. | ||||
| 659 | Fingerprinter fp(sig, is_static()); | ||||
| 660 | set_size_of_parameters(fp.size_of_parameters()); | ||||
| 661 | constMethod()->set_result_type(fp.return_type()); | ||||
| 662 | constMethod()->set_fingerprint(fp.fingerprint()); | ||||
| 663 | } | ||||
| 664 | |||||
| 665 | bool Method::is_vanilla_constructor() const { | ||||
| 666 | // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method | ||||
| 667 | // which only calls the superclass vanilla constructor and possibly does stores of | ||||
| 668 | // zero constants to local fields: | ||||
| 669 | // | ||||
| 670 | // aload_0 | ||||
| 671 | // invokespecial | ||||
| 672 | // indexbyte1 | ||||
| 673 | // indexbyte2 | ||||
| 674 | // | ||||
| 675 | // followed by an (optional) sequence of: | ||||
| 676 | // | ||||
| 677 | // aload_0 | ||||
| 678 | // aconst_null / iconst_0 / fconst_0 / dconst_0 | ||||
| 679 | // putfield | ||||
| 680 | // indexbyte1 | ||||
| 681 | // indexbyte2 | ||||
| 682 | // | ||||
| 683 | // followed by: | ||||
| 684 | // | ||||
| 685 | // return | ||||
| 686 | |||||
| 687 | assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors")do { if (!(name() == vmSymbols::object_initializer_name())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 687, "assert(" "name() == vmSymbols::object_initializer_name()" ") failed", "Should only be called for default constructors" ); ::breakpoint(); } } while (0); | ||||
| 688 | assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors")do { if (!(signature() == vmSymbols::void_method_signature()) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 688, "assert(" "signature() == vmSymbols::void_method_signature()" ") failed", "Should only be called for default constructors" ); ::breakpoint(); } } while (0); | ||||
| 689 | int size = code_size(); | ||||
| 690 | // Check if size match | ||||
| 691 | if (size == 0 || size % 5 != 0) return false; | ||||
| 692 | address cb = code_base(); | ||||
| 693 | int last = size - 1; | ||||
| 694 | if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) { | ||||
| 695 | // Does not call superclass default constructor | ||||
| 696 | return false; | ||||
| 697 | } | ||||
| 698 | // Check optional sequence | ||||
| 699 | for (int i = 4; i < last; i += 5) { | ||||
| 700 | if (cb[i] != Bytecodes::_aload_0) return false; | ||||
| 701 | if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false; | ||||
| 702 | if (cb[i+2] != Bytecodes::_putfield) return false; | ||||
| 703 | } | ||||
| 704 | return true; | ||||
| 705 | } | ||||
| 706 | |||||
| 707 | |||||
| 708 | bool Method::compute_has_loops_flag() { | ||||
| 709 | BytecodeStream bcs(methodHandle(Thread::current(), this)); | ||||
| 710 | Bytecodes::Code bc; | ||||
| 711 | |||||
| 712 | while ((bc = bcs.next()) >= 0) { | ||||
| 713 | switch (bc) { | ||||
| 714 | case Bytecodes::_ifeq: | ||||
| 715 | case Bytecodes::_ifnull: | ||||
| 716 | case Bytecodes::_iflt: | ||||
| 717 | case Bytecodes::_ifle: | ||||
| 718 | case Bytecodes::_ifne: | ||||
| 719 | case Bytecodes::_ifnonnull: | ||||
| 720 | case Bytecodes::_ifgt: | ||||
| 721 | case Bytecodes::_ifge: | ||||
| 722 | case Bytecodes::_if_icmpeq: | ||||
| 723 | case Bytecodes::_if_icmpne: | ||||
| 724 | case Bytecodes::_if_icmplt: | ||||
| 725 | case Bytecodes::_if_icmpgt: | ||||
| 726 | case Bytecodes::_if_icmple: | ||||
| 727 | case Bytecodes::_if_icmpge: | ||||
| 728 | case Bytecodes::_if_acmpeq: | ||||
| 729 | case Bytecodes::_if_acmpne: | ||||
| 730 | case Bytecodes::_goto: | ||||
| 731 | case Bytecodes::_jsr: | ||||
| 732 | if (bcs.dest() < bcs.next_bci()) _access_flags.set_has_loops(); | ||||
| 733 | break; | ||||
| 734 | |||||
| 735 | case Bytecodes::_goto_w: | ||||
| 736 | case Bytecodes::_jsr_w: | ||||
| 737 | if (bcs.dest_w() < bcs.next_bci()) _access_flags.set_has_loops(); | ||||
| 738 | break; | ||||
| 739 | |||||
| 740 | case Bytecodes::_lookupswitch: { | ||||
| 741 | Bytecode_lookupswitch lookupswitch(this, bcs.bcp()); | ||||
| 742 | if (lookupswitch.default_offset() < 0) { | ||||
| 743 | _access_flags.set_has_loops(); | ||||
| 744 | } else { | ||||
| 745 | for (int i = 0; i < lookupswitch.number_of_pairs(); ++i) { | ||||
| 746 | LookupswitchPair pair = lookupswitch.pair_at(i); | ||||
| 747 | if (pair.offset() < 0) { | ||||
| 748 | _access_flags.set_has_loops(); | ||||
| 749 | break; | ||||
| 750 | } | ||||
| 751 | } | ||||
| 752 | } | ||||
| 753 | break; | ||||
| 754 | } | ||||
| 755 | case Bytecodes::_tableswitch: { | ||||
| 756 | Bytecode_tableswitch tableswitch(this, bcs.bcp()); | ||||
| 757 | if (tableswitch.default_offset() < 0) { | ||||
| 758 | _access_flags.set_has_loops(); | ||||
| 759 | } else { | ||||
| 760 | for (int i = 0; i < tableswitch.length(); ++i) { | ||||
| 761 | if (tableswitch.dest_offset_at(i) < 0) { | ||||
| 762 | _access_flags.set_has_loops(); | ||||
| 763 | } | ||||
| 764 | } | ||||
| 765 | } | ||||
| 766 | break; | ||||
| 767 | } | ||||
| 768 | default: | ||||
| 769 | break; | ||||
| 770 | } | ||||
| 771 | } | ||||
| 772 | _access_flags.set_loops_flag_init(); | ||||
| 773 | return _access_flags.has_loops(); | ||||
| 774 | } | ||||
| 775 | |||||
| 776 | bool Method::is_final_method(AccessFlags class_access_flags) const { | ||||
| 777 | // or "does_not_require_vtable_entry" | ||||
| 778 | // default method or overpass can occur, is not final (reuses vtable entry) | ||||
| 779 | // private methods in classes get vtable entries for backward class compatibility. | ||||
| 780 | if (is_overpass() || is_default_method()) return false; | ||||
| 781 | return is_final() || class_access_flags.is_final(); | ||||
| 782 | } | ||||
| 783 | |||||
| 784 | bool Method::is_final_method() const { | ||||
| 785 | return is_final_method(method_holder()->access_flags()); | ||||
| 786 | } | ||||
| 787 | |||||
| 788 | bool Method::is_default_method() const { | ||||
| 789 | if (method_holder() != NULL__null && | ||||
| 790 | method_holder()->is_interface() && | ||||
| 791 | !is_abstract() && !is_private()) { | ||||
| 792 | return true; | ||||
| 793 | } else { | ||||
| 794 | return false; | ||||
| 795 | } | ||||
| 796 | } | ||||
| 797 | |||||
| 798 | bool Method::can_be_statically_bound(AccessFlags class_access_flags) const { | ||||
| 799 | if (is_final_method(class_access_flags)) return true; | ||||
| 800 | #ifdef ASSERT1 | ||||
| 801 | ResourceMark rm; | ||||
| 802 | bool is_nonv = (vtable_index() == nonvirtual_vtable_index); | ||||
| 803 | if (class_access_flags.is_interface()) { | ||||
| 804 | assert(is_nonv == is_static() || is_nonv == is_private(),do { if (!(is_nonv == is_static() || is_nonv == is_private()) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 806, "assert(" "is_nonv == is_static() || is_nonv == is_private()" ") failed", "nonvirtual unexpected for non-static, non-private: %s" , name_and_sig_as_C_string()); ::breakpoint(); } } while (0) | ||||
| 805 | "nonvirtual unexpected for non-static, non-private: %s",do { if (!(is_nonv == is_static() || is_nonv == is_private()) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 806, "assert(" "is_nonv == is_static() || is_nonv == is_private()" ") failed", "nonvirtual unexpected for non-static, non-private: %s" , name_and_sig_as_C_string()); ::breakpoint(); } } while (0) | ||||
| 806 | name_and_sig_as_C_string())do { if (!(is_nonv == is_static() || is_nonv == is_private()) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 806, "assert(" "is_nonv == is_static() || is_nonv == is_private()" ") failed", "nonvirtual unexpected for non-static, non-private: %s" , name_and_sig_as_C_string()); ::breakpoint(); } } while (0); | ||||
| 807 | } | ||||
| 808 | #endif | ||||
| 809 | assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question")do { if (!(valid_vtable_index() || valid_itable_index())) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 809, "assert(" "valid_vtable_index() || valid_itable_index()" ") failed", "method must be linked before we ask this question" ); ::breakpoint(); } } while (0); | ||||
| 810 | return vtable_index() == nonvirtual_vtable_index; | ||||
| 811 | } | ||||
| 812 | |||||
| 813 | bool Method::can_be_statically_bound() const { | ||||
| 814 | return can_be_statically_bound(method_holder()->access_flags()); | ||||
| 815 | } | ||||
| 816 | |||||
| 817 | bool Method::can_be_statically_bound(InstanceKlass* context) const { | ||||
| 818 | return (method_holder() == context) && can_be_statically_bound(); | ||||
| 819 | } | ||||
| 820 | |||||
| 821 | /** | ||||
| 822 | * Returns false if this is one of specially treated methods for | ||||
| 823 | * which we have to provide stack trace in throw in compiled code. | ||||
| 824 | * Returns true otherwise. | ||||
| 825 | */ | ||||
| 826 | bool Method::can_omit_stack_trace() { | ||||
| 827 | if (klass_name() == vmSymbols::sun_invoke_util_ValueConversions()) { | ||||
| 828 | return false; // All methods in sun.invoke.util.ValueConversions | ||||
| 829 | } | ||||
| 830 | return true; | ||||
| 831 | } | ||||
| 832 | |||||
| 833 | bool Method::is_accessor() const { | ||||
| 834 | return is_getter() || is_setter(); | ||||
| 835 | } | ||||
| 836 | |||||
| 837 | bool Method::is_getter() const { | ||||
| 838 | if (code_size() != 5) return false; | ||||
| 839 | if (size_of_parameters() != 1) return false; | ||||
| 840 | if (java_code_at(0) != Bytecodes::_aload_0) return false; | ||||
| 841 | if (java_code_at(1) != Bytecodes::_getfield) return false; | ||||
| 842 | switch (java_code_at(4)) { | ||||
| 843 | case Bytecodes::_ireturn: | ||||
| 844 | case Bytecodes::_lreturn: | ||||
| 845 | case Bytecodes::_freturn: | ||||
| 846 | case Bytecodes::_dreturn: | ||||
| 847 | case Bytecodes::_areturn: | ||||
| 848 | break; | ||||
| 849 | default: | ||||
| 850 | return false; | ||||
| 851 | } | ||||
| 852 | return true; | ||||
| 853 | } | ||||
| 854 | |||||
| 855 | bool Method::is_setter() const { | ||||
| 856 | if (code_size() != 6) return false; | ||||
| 857 | if (java_code_at(0) != Bytecodes::_aload_0) return false; | ||||
| 858 | switch (java_code_at(1)) { | ||||
| 859 | case Bytecodes::_iload_1: | ||||
| 860 | case Bytecodes::_aload_1: | ||||
| 861 | case Bytecodes::_fload_1: | ||||
| 862 | if (size_of_parameters() != 2) return false; | ||||
| 863 | break; | ||||
| 864 | case Bytecodes::_dload_1: | ||||
| 865 | case Bytecodes::_lload_1: | ||||
| 866 | if (size_of_parameters() != 3) return false; | ||||
| 867 | break; | ||||
| 868 | default: | ||||
| 869 | return false; | ||||
| 870 | } | ||||
| 871 | if (java_code_at(2) != Bytecodes::_putfield) return false; | ||||
| 872 | if (java_code_at(5) != Bytecodes::_return) return false; | ||||
| 873 | return true; | ||||
| 874 | } | ||||
| 875 | |||||
| 876 | bool Method::is_constant_getter() const { | ||||
| 877 | int last_index = code_size() - 1; | ||||
| 878 | // Check if the first 1-3 bytecodes are a constant push | ||||
| 879 | // and the last bytecode is a return. | ||||
| 880 | return (2 <= code_size() && code_size() <= 4 && | ||||
| 881 | Bytecodes::is_const(java_code_at(0)) && | ||||
| 882 | Bytecodes::length_for(java_code_at(0)) == last_index && | ||||
| 883 | Bytecodes::is_return(java_code_at(last_index))); | ||||
| 884 | } | ||||
| 885 | |||||
| 886 | bool Method::is_initializer() const { | ||||
| 887 | return is_object_initializer() || is_static_initializer(); | ||||
| 888 | } | ||||
| 889 | |||||
| 890 | bool Method::has_valid_initializer_flags() const { | ||||
| 891 | return (is_static() || | ||||
| 892 | method_holder()->major_version() < 51); | ||||
| 893 | } | ||||
| 894 | |||||
| 895 | bool Method::is_static_initializer() const { | ||||
| 896 | // For classfiles version 51 or greater, ensure that the clinit method is | ||||
| 897 | // static. Non-static methods with the name "<clinit>" are not static | ||||
| 898 | // initializers. (older classfiles exempted for backward compatibility) | ||||
| 899 | return name() == vmSymbols::class_initializer_name() && | ||||
| 900 | has_valid_initializer_flags(); | ||||
| 901 | } | ||||
| 902 | |||||
| 903 | bool Method::is_object_initializer() const { | ||||
| 904 | return name() == vmSymbols::object_initializer_name(); | ||||
| 905 | } | ||||
| 906 | |||||
| 907 | bool Method::needs_clinit_barrier() const { | ||||
| 908 | return is_static() && !method_holder()->is_initialized(); | ||||
| 909 | } | ||||
| 910 | |||||
| 911 | objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPSJavaThread* __the_thread__) { | ||||
| 912 | int length = method->checked_exceptions_length(); | ||||
| 913 | if (length == 0) { // common case | ||||
| 914 | return objArrayHandle(THREAD__the_thread__, Universe::the_empty_class_array()); | ||||
| 915 | } else { | ||||
| 916 | methodHandle h_this(THREAD__the_thread__, method); | ||||
| 917 | objArrayOop m_oop = oopFactory::new_objArray(vmClasses::Class_klass(), length, CHECK_(objArrayHandle())__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return objArrayHandle(); (void)(0); | ||||
| 918 | objArrayHandle mirrors (THREAD__the_thread__, m_oop); | ||||
| 919 | for (int i = 0; i < length; i++) { | ||||
| 920 | CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe | ||||
| 921 | Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle())__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return objArrayHandle(); (void)(0); | ||||
| 922 | if (log_is_enabled(Warning, exceptions)(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Warning)) && | ||||
| 923 | !k->is_subclass_of(vmClasses::Throwable_klass())) { | ||||
| 924 | ResourceMark rm(THREAD__the_thread__); | ||||
| 925 | log_warning(exceptions)(!(LogImpl<(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Warning))) ? (void)0 : LogImpl <(LogTag::_exceptions), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Warning>( | ||||
| 926 | "Class %s in throws clause of method %s is not a subtype of class java.lang.Throwable", | ||||
| 927 | k->external_name(), method->external_name()); | ||||
| 928 | } | ||||
| 929 | mirrors->obj_at_put(i, k->java_mirror()); | ||||
| 930 | } | ||||
| 931 | return mirrors; | ||||
| 932 | } | ||||
| 933 | }; | ||||
| 934 | |||||
| 935 | |||||
| 936 | int Method::line_number_from_bci(int bci) const { | ||||
| 937 | int best_bci = 0; | ||||
| 938 | int best_line = -1; | ||||
| 939 | if (bci == SynchronizationEntryBCI) bci = 0; | ||||
| 940 | if (0 <= bci && bci < code_size() && has_linenumber_table()) { | ||||
| 941 | // The line numbers are a short array of 2-tuples [start_pc, line_number]. | ||||
| 942 | // Not necessarily sorted and not necessarily one-to-one. | ||||
| 943 | CompressedLineNumberReadStream stream(compressed_linenumber_table()); | ||||
| 944 | while (stream.read_pair()) { | ||||
| 945 | if (stream.bci() == bci) { | ||||
| 946 | // perfect match | ||||
| 947 | return stream.line(); | ||||
| 948 | } else { | ||||
| 949 | // update best_bci/line | ||||
| 950 | if (stream.bci() < bci && stream.bci() >= best_bci) { | ||||
| 951 | best_bci = stream.bci(); | ||||
| 952 | best_line = stream.line(); | ||||
| 953 | } | ||||
| 954 | } | ||||
| 955 | } | ||||
| 956 | } | ||||
| 957 | return best_line; | ||||
| 958 | } | ||||
| 959 | |||||
| 960 | |||||
| 961 | bool Method::is_klass_loaded_by_klass_index(int klass_index) const { | ||||
| 962 | if( constants()->tag_at(klass_index).is_unresolved_klass() ) { | ||||
| 963 | Thread *thread = Thread::current(); | ||||
| 964 | Symbol* klass_name = constants()->klass_name_at(klass_index); | ||||
| 965 | Handle loader(thread, method_holder()->class_loader()); | ||||
| 966 | Handle prot (thread, method_holder()->protection_domain()); | ||||
| 967 | return SystemDictionary::find_instance_klass(klass_name, loader, prot) != NULL__null; | ||||
| 968 | } else { | ||||
| 969 | return true; | ||||
| 970 | } | ||||
| 971 | } | ||||
| 972 | |||||
| 973 | |||||
| 974 | bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { | ||||
| 975 | int klass_index = constants()->klass_ref_index_at(refinfo_index); | ||||
| 976 | if (must_be_resolved) { | ||||
| 977 | // Make sure klass is resolved in constantpool. | ||||
| 978 | if (constants()->tag_at(klass_index).is_unresolved_klass()) return false; | ||||
| 979 | } | ||||
| 980 | return is_klass_loaded_by_klass_index(klass_index); | ||||
| 981 | } | ||||
| 982 | |||||
| 983 | |||||
| 984 | void Method::set_native_function(address function, bool post_event_flag) { | ||||
| 985 | assert(function != NULL, "use clear_native_function to unregister natives")do { if (!(function != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 985, "assert(" "function != __null" ") failed", "use clear_native_function to unregister natives" ); ::breakpoint(); } } while (0); | ||||
| 986 | assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "")do { if (!(!is_method_handle_intrinsic() || function == SharedRuntime ::native_method_throw_unsatisfied_link_error_entry())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 986, "assert(" "!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry()" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 987 | address* native_function = native_function_addr(); | ||||
| 988 | |||||
| 989 | // We can see racers trying to place the same native function into place. Once | ||||
| 990 | // is plenty. | ||||
| 991 | address current = *native_function; | ||||
| 992 | if (current == function) return; | ||||
| 993 | if (post_event_flag && JvmtiExport::should_post_native_method_bind() && | ||||
| 994 | function != NULL__null) { | ||||
| 995 | // native_method_throw_unsatisfied_link_error_entry() should only | ||||
| 996 | // be passed when post_event_flag is false. | ||||
| 997 | assert(function !=do { if (!(function != SharedRuntime::native_method_throw_unsatisfied_link_error_entry ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 999, "assert(" "function != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()" ") failed", "post_event_flag mis-match"); ::breakpoint(); } } while (0) | ||||
| 998 | SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),do { if (!(function != SharedRuntime::native_method_throw_unsatisfied_link_error_entry ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 999, "assert(" "function != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()" ") failed", "post_event_flag mis-match"); ::breakpoint(); } } while (0) | ||||
| 999 | "post_event_flag mis-match")do { if (!(function != SharedRuntime::native_method_throw_unsatisfied_link_error_entry ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 999, "assert(" "function != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()" ") failed", "post_event_flag mis-match"); ::breakpoint(); } } while (0); | ||||
| 1000 | |||||
| 1001 | // post the bind event, and possible change the bind function | ||||
| 1002 | JvmtiExport::post_native_method_bind(this, &function); | ||||
| 1003 | } | ||||
| 1004 | *native_function = function; | ||||
| 1005 | // This function can be called more than once. We must make sure that we always | ||||
| 1006 | // use the latest registered method -> check if a stub already has been generated. | ||||
| 1007 | // If so, we have to make it not_entrant. | ||||
| 1008 | CompiledMethod* nm = code(); // Put it into local variable to guard against concurrent updates | ||||
| 1009 | if (nm != NULL__null) { | ||||
| 1010 | nm->make_not_entrant(); | ||||
| 1011 | } | ||||
| 1012 | } | ||||
| 1013 | |||||
| 1014 | |||||
| 1015 | bool Method::has_native_function() const { | ||||
| 1016 | if (is_method_handle_intrinsic()) | ||||
| 1017 | return false; // special-cased in SharedRuntime::generate_native_wrapper | ||||
| 1018 | address func = native_function(); | ||||
| 1019 | return (func != NULL__null && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); | ||||
| 1020 | } | ||||
| 1021 | |||||
| 1022 | |||||
| 1023 | void Method::clear_native_function() { | ||||
| 1024 | // Note: is_method_handle_intrinsic() is allowed here. | ||||
| 1025 | set_native_function( | ||||
| 1026 | SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), | ||||
| 1027 | !native_bind_event_is_interesting); | ||||
| 1028 | this->unlink_code(); | ||||
| 1029 | } | ||||
| 1030 | |||||
| 1031 | |||||
| 1032 | void Method::set_signature_handler(address handler) { | ||||
| 1033 | address* signature_handler = signature_handler_addr(); | ||||
| 1034 | *signature_handler = handler; | ||||
| 1035 | } | ||||
| 1036 | |||||
| 1037 | |||||
| 1038 | void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) { | ||||
| 1039 | assert(reason != NULL, "must provide a reason")do { if (!(reason != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1039, "assert(" "reason != __null" ") failed", "must provide a reason" ); ::breakpoint(); } } while (0); | ||||
| 1040 | if (PrintCompilation && report) { | ||||
| 1041 | ttyLocker ttyl; | ||||
| 1042 | tty->print("made not %scompilable on ", is_osr ? "OSR " : ""); | ||||
| 1043 | if (comp_level == CompLevel_all) { | ||||
| 1044 | tty->print("all levels "); | ||||
| 1045 | } else { | ||||
| 1046 | tty->print("level %d ", comp_level); | ||||
| 1047 | } | ||||
| 1048 | this->print_short_name(tty); | ||||
| 1049 | int size = this->code_size(); | ||||
| 1050 | if (size > 0) { | ||||
| 1051 | tty->print(" (%d bytes)", size); | ||||
| 1052 | } | ||||
| 1053 | if (reason != NULL__null) { | ||||
| 1054 | tty->print(" %s", reason); | ||||
| 1055 | } | ||||
| 1056 | tty->cr(); | ||||
| 1057 | } | ||||
| 1058 | if ((TraceDeoptimization || LogCompilation) && (xtty != NULL__null)) { | ||||
| 1059 | ttyLocker ttyl; | ||||
| 1060 | xtty->begin_elem("make_not_compilable thread='" UINTX_FORMAT"%" "l" "u" "' osr='%d' level='%d'", | ||||
| 1061 | os::current_thread_id(), is_osr, comp_level); | ||||
| 1062 | if (reason != NULL__null) { | ||||
| 1063 | xtty->print(" reason=\'%s\'", reason); | ||||
| 1064 | } | ||||
| 1065 | xtty->method(this); | ||||
| 1066 | xtty->stamp(); | ||||
| 1067 | xtty->end_elem(); | ||||
| 1068 | } | ||||
| 1069 | } | ||||
| 1070 | |||||
| 1071 | bool Method::is_always_compilable() const { | ||||
| 1072 | // Generated adapters must be compiled | ||||
| 1073 | if (is_method_handle_intrinsic() && is_synthetic()) { | ||||
| 1074 | assert(!is_not_c1_compilable(), "sanity check")do { if (!(!is_not_c1_compilable())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1074, "assert(" "!is_not_c1_compilable()" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | ||||
| 1075 | assert(!is_not_c2_compilable(), "sanity check")do { if (!(!is_not_c2_compilable())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1075, "assert(" "!is_not_c2_compilable()" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | ||||
| 1076 | return true; | ||||
| 1077 | } | ||||
| 1078 | |||||
| 1079 | return false; | ||||
| 1080 | } | ||||
| 1081 | |||||
| 1082 | bool Method::is_not_compilable(int comp_level) const { | ||||
| 1083 | if (number_of_breakpoints() > 0) | ||||
| 1084 | return true; | ||||
| 1085 | if (is_always_compilable()) | ||||
| 1086 | return false; | ||||
| 1087 | if (comp_level == CompLevel_any) | ||||
| 1088 | return is_not_c1_compilable() && is_not_c2_compilable(); | ||||
| 1089 | if (is_c1_compile(comp_level)) | ||||
| 1090 | return is_not_c1_compilable(); | ||||
| 1091 | if (is_c2_compile(comp_level)) | ||||
| 1092 | return is_not_c2_compilable(); | ||||
| 1093 | return false; | ||||
| 1094 | } | ||||
| 1095 | |||||
| 1096 | // call this when compiler finds that this method is not compilable | ||||
| 1097 | void Method::set_not_compilable(const char* reason, int comp_level, bool report) { | ||||
| 1098 | if (is_always_compilable()) { | ||||
| 1099 | // Don't mark a method which should be always compilable | ||||
| 1100 | return; | ||||
| 1101 | } | ||||
| 1102 | print_made_not_compilable(comp_level, /*is_osr*/ false, report, reason); | ||||
| 1103 | if (comp_level == CompLevel_all) { | ||||
| 1104 | set_not_c1_compilable(); | ||||
| 1105 | set_not_c2_compilable(); | ||||
| 1106 | } else { | ||||
| 1107 | if (is_c1_compile(comp_level)) | ||||
| 1108 | set_not_c1_compilable(); | ||||
| 1109 | if (is_c2_compile(comp_level)) | ||||
| 1110 | set_not_c2_compilable(); | ||||
| 1111 | } | ||||
| 1112 | assert(!CompilationPolicy::can_be_compiled(methodHandle(Thread::current(), this), comp_level), "sanity check")do { if (!(!CompilationPolicy::can_be_compiled(methodHandle(Thread ::current(), this), comp_level))) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1112, "assert(" "!CompilationPolicy::can_be_compiled(methodHandle(Thread::current(), this), comp_level)" ") failed", "sanity check"); ::breakpoint(); } } while (0); | ||||
| 1113 | } | ||||
| 1114 | |||||
| 1115 | bool Method::is_not_osr_compilable(int comp_level) const { | ||||
| 1116 | if (is_not_compilable(comp_level)) | ||||
| 1117 | return true; | ||||
| 1118 | if (comp_level == CompLevel_any) | ||||
| 1119 | return is_not_c1_osr_compilable() && is_not_c2_osr_compilable(); | ||||
| 1120 | if (is_c1_compile(comp_level)) | ||||
| 1121 | return is_not_c1_osr_compilable(); | ||||
| 1122 | if (is_c2_compile(comp_level)) | ||||
| 1123 | return is_not_c2_osr_compilable(); | ||||
| 1124 | return false; | ||||
| 1125 | } | ||||
| 1126 | |||||
| 1127 | void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) { | ||||
| 1128 | print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason); | ||||
| 1129 | if (comp_level == CompLevel_all) { | ||||
| 1130 | set_not_c1_osr_compilable(); | ||||
| 1131 | set_not_c2_osr_compilable(); | ||||
| 1132 | } else { | ||||
| 1133 | if (is_c1_compile(comp_level)) | ||||
| 1134 | set_not_c1_osr_compilable(); | ||||
| 1135 | if (is_c2_compile(comp_level)) | ||||
| 1136 | set_not_c2_osr_compilable(); | ||||
| 1137 | } | ||||
| 1138 | assert(!CompilationPolicy::can_be_osr_compiled(methodHandle(Thread::current(), this), comp_level), "sanity check")do { if (!(!CompilationPolicy::can_be_osr_compiled(methodHandle (Thread::current(), this), comp_level))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1138, "assert(" "!CompilationPolicy::can_be_osr_compiled(methodHandle(Thread::current(), this), comp_level)" ") failed", "sanity check"); ::breakpoint(); } } while (0); | ||||
| 1139 | } | ||||
| 1140 | |||||
| 1141 | // Revert to using the interpreter and clear out the nmethod | ||||
| 1142 | void Method::clear_code() { | ||||
| 1143 | // this may be NULL if c2i adapters have not been made yet | ||||
| 1144 | // Only should happen at allocate time. | ||||
| 1145 | if (adapter() == NULL__null) { | ||||
| 1146 | _from_compiled_entry = NULL__null; | ||||
| 1147 | } else { | ||||
| 1148 | _from_compiled_entry = adapter()->get_c2i_entry(); | ||||
| 1149 | } | ||||
| 1150 | OrderAccess::storestore(); | ||||
| 1151 | _from_interpreted_entry = _i2i_entry; | ||||
| 1152 | OrderAccess::storestore(); | ||||
| 1153 | _code = NULL__null; | ||||
| 1154 | } | ||||
| 1155 | |||||
| 1156 | void Method::unlink_code(CompiledMethod *compare) { | ||||
| 1157 | MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL__null : CompiledMethod_lock, Mutex::_no_safepoint_check_flag); | ||||
| 1158 | // We need to check if either the _code or _from_compiled_code_entry_point | ||||
| 1159 | // refer to this nmethod because there is a race in setting these two fields | ||||
| 1160 | // in Method* as seen in bugid 4947125. | ||||
| 1161 | // If the vep() points to the zombie nmethod, the memory for the nmethod | ||||
| 1162 | // could be flushed and the compiler and vtable stubs could still call | ||||
| 1163 | // through it. | ||||
| 1164 | if (code() == compare || | ||||
| 1165 | from_compiled_entry() == compare->verified_entry_point()) { | ||||
| 1166 | clear_code(); | ||||
| 1167 | } | ||||
| 1168 | } | ||||
| 1169 | |||||
| 1170 | void Method::unlink_code() { | ||||
| 1171 | MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL__null : CompiledMethod_lock, Mutex::_no_safepoint_check_flag); | ||||
| 1172 | clear_code(); | ||||
| 1173 | } | ||||
| 1174 | |||||
| 1175 | #if INCLUDE_CDS1 | ||||
| 1176 | // Called by class data sharing to remove any entry points (which are not shared) | ||||
| 1177 | void Method::unlink_method() { | ||||
| 1178 | Arguments::assert_is_dumping_archive(); | ||||
| 1179 | _code = NULL__null; | ||||
| 1180 | _adapter = NULL__null; | ||||
| 1181 | _i2i_entry = NULL__null; | ||||
| 1182 | _from_compiled_entry = NULL__null; | ||||
| 1183 | _from_interpreted_entry = NULL__null; | ||||
| 1184 | |||||
| 1185 | if (is_native()) { | ||||
| 1186 | *native_function_addr() = NULL__null; | ||||
| 1187 | set_signature_handler(NULL__null); | ||||
| 1188 | } | ||||
| 1189 | NOT_PRODUCT(set_compiled_invocation_count(0);)set_compiled_invocation_count(0); | ||||
| 1190 | |||||
| 1191 | set_method_data(NULL__null); | ||||
| 1192 | clear_method_counters(); | ||||
| 1193 | } | ||||
| 1194 | #endif | ||||
| 1195 | |||||
| 1196 | // Called when the method_holder is getting linked. Setup entrypoints so the method | ||||
| 1197 | // is ready to be called from interpreter, compiler, and vtables. | ||||
| 1198 | void Method::link_method(const methodHandle& h_method, TRAPSJavaThread* __the_thread__) { | ||||
| 1199 | // If the code cache is full, we may reenter this function for the | ||||
| 1200 | // leftover methods that weren't linked. | ||||
| 1201 | if (_i2i_entry != NULL__null) { | ||||
| 1202 | return; | ||||
| 1203 | } | ||||
| 1204 | assert( _code == NULL, "nothing compiled yet" )do { if (!(_code == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1204, "assert(" "_code == __null" ") failed", "nothing compiled yet" ); ::breakpoint(); } } while (0); | ||||
| 1205 | |||||
| 1206 | // Setup interpreter entrypoint | ||||
| 1207 | assert(this == h_method(), "wrong h_method()" )do { if (!(this == h_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1207, "assert(" "this == h_method()" ") failed", "wrong h_method()" ); ::breakpoint(); } } while (0); | ||||
| 1208 | |||||
| 1209 | assert(adapter() == NULL, "init'd to NULL")do { if (!(adapter() == __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1209, "assert(" "adapter() == __null" ") failed", "init'd to NULL" ); ::breakpoint(); } } while (0); | ||||
| 1210 | address entry = Interpreter::entry_for_method(h_method); | ||||
| 1211 | assert(entry != NULL, "interpreter entry must be non-null")do { if (!(entry != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1211, "assert(" "entry != __null" ") failed", "interpreter entry must be non-null" ); ::breakpoint(); } } while (0); | ||||
| 1212 | // Sets both _i2i_entry and _from_interpreted_entry | ||||
| 1213 | set_interpreter_entry(entry); | ||||
| 1214 | |||||
| 1215 | // Don't overwrite already registered native entries. | ||||
| 1216 | if (is_native() && !has_native_function()) { | ||||
| 1217 | set_native_function( | ||||
| 1218 | SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), | ||||
| 1219 | !native_bind_event_is_interesting); | ||||
| 1220 | } | ||||
| 1221 | |||||
| 1222 | // Setup compiler entrypoint. This is made eagerly, so we do not need | ||||
| 1223 | // special handling of vtables. An alternative is to make adapters more | ||||
| 1224 | // lazily by calling make_adapter() from from_compiled_entry() for the | ||||
| 1225 | // normal calls. For vtable calls life gets more complicated. When a | ||||
| 1226 | // call-site goes mega-morphic we need adapters in all methods which can be | ||||
| 1227 | // called from the vtable. We need adapters on such methods that get loaded | ||||
| 1228 | // later. Ditto for mega-morphic itable calls. If this proves to be a | ||||
| 1229 | // problem we'll make these lazily later. | ||||
| 1230 | (void) make_adapters(h_method, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); | ||||
| 1231 | |||||
| 1232 | // ONLY USE the h_method now as make_adapter may have blocked | ||||
| 1233 | } | ||||
| 1234 | |||||
| 1235 | address Method::make_adapters(const methodHandle& mh, TRAPSJavaThread* __the_thread__) { | ||||
| 1236 | // Adapters for compiled code are made eagerly here. They are fairly | ||||
| 1237 | // small (generally < 100 bytes) and quick to make (and cached and shared) | ||||
| 1238 | // so making them eagerly shouldn't be too expensive. | ||||
| 1239 | AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh); | ||||
| 1240 | if (adapter == NULL__null ) { | ||||
| 1241 | if (!is_init_completed()) { | ||||
| 1242 | // Don't throw exceptions during VM initialization because java.lang.* classes | ||||
| 1243 | // might not have been initialized, causing problems when constructing the | ||||
| 1244 | // Java exception object. | ||||
| 1245 | vm_exit_during_initialization("Out of space in CodeCache for adapters"); | ||||
| 1246 | } else { | ||||
| 1247 | THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters"){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1247, vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters" ); return __null; }; | ||||
| 1248 | } | ||||
| 1249 | } | ||||
| 1250 | |||||
| 1251 | mh->set_adapter_entry(adapter); | ||||
| 1252 | mh->_from_compiled_entry = adapter->get_c2i_entry(); | ||||
| 1253 | return adapter->get_c2i_entry(); | ||||
| 1254 | } | ||||
| 1255 | |||||
| 1256 | void Method::restore_unshareable_info(TRAPSJavaThread* __the_thread__) { | ||||
| 1257 | assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored")do { if (!(is_method() && is_valid_method(this))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1257, "assert(" "is_method() && is_valid_method(this)" ") failed", "ensure C++ vtable is restored"); ::breakpoint() ; } } while (0); | ||||
| |||||
| 1258 | } | ||||
| 1259 | |||||
| 1260 | address Method::from_compiled_entry_no_trampoline() const { | ||||
| 1261 | CompiledMethod *code = Atomic::load_acquire(&_code); | ||||
| 1262 | if (code) { | ||||
| 1263 | return code->verified_entry_point(); | ||||
| 1264 | } else { | ||||
| 1265 | return adapter()->get_c2i_entry(); | ||||
| 1266 | } | ||||
| 1267 | } | ||||
| 1268 | |||||
| 1269 | // The verified_code_entry() must be called when a invoke is resolved | ||||
| 1270 | // on this method. | ||||
| 1271 | |||||
| 1272 | // It returns the compiled code entry point, after asserting not null. | ||||
| 1273 | // This function is called after potential safepoints so that nmethod | ||||
| 1274 | // or adapter that it points to is still live and valid. | ||||
| 1275 | // This function must not hit a safepoint! | ||||
| 1276 | address Method::verified_code_entry() { | ||||
| 1277 | debug_only(NoSafepointVerifier nsv;)NoSafepointVerifier nsv; | ||||
| 1278 | assert(_from_compiled_entry != NULL, "must be set")do { if (!(_from_compiled_entry != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1278, "assert(" "_from_compiled_entry != __null" ") failed" , "must be set"); ::breakpoint(); } } while (0); | ||||
| 1279 | return _from_compiled_entry; | ||||
| 1280 | } | ||||
| 1281 | |||||
| 1282 | // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all | ||||
| 1283 | // (could be racing a deopt). | ||||
| 1284 | // Not inline to avoid circular ref. | ||||
| 1285 | bool Method::check_code() const { | ||||
| 1286 | // cached in a register or local. There's a race on the value of the field. | ||||
| 1287 | CompiledMethod *code = Atomic::load_acquire(&_code); | ||||
| 1288 | return code == NULL__null || (code->method() == NULL__null) || (code->method() == (Method*)this && !code->is_osr_method()); | ||||
| 1289 | } | ||||
| 1290 | |||||
| 1291 | // Install compiled code. Instantly it can execute. | ||||
| 1292 | void Method::set_code(const methodHandle& mh, CompiledMethod *code) { | ||||
| 1293 | assert_lock_strong(CompiledMethod_lock); | ||||
| 1294 | assert( code, "use clear_code to remove code" )do { if (!(code)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1294, "assert(" "code" ") failed", "use clear_code to remove code" ); ::breakpoint(); } } while (0); | ||||
| 1295 | assert( mh->check_code(), "" )do { if (!(mh->check_code())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1295, "assert(" "mh->check_code()" ") failed", ""); ::breakpoint (); } } while (0); | ||||
| 1296 | |||||
| 1297 | guarantee(mh->adapter() != NULL, "Adapter blob must already exist!")do { if (!(mh->adapter() != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1297, "guarantee(" "mh->adapter() != NULL" ") failed", "Adapter blob must already exist!" ); ::breakpoint(); } } while (0); | ||||
| 1298 | |||||
| 1299 | // These writes must happen in this order, because the interpreter will | ||||
| 1300 | // directly jump to from_interpreted_entry which jumps to an i2c adapter | ||||
| 1301 | // which jumps to _from_compiled_entry. | ||||
| 1302 | mh->_code = code; // Assign before allowing compiled code to exec | ||||
| 1303 | |||||
| 1304 | int comp_level = code->comp_level(); | ||||
| 1305 | // In theory there could be a race here. In practice it is unlikely | ||||
| 1306 | // and not worth worrying about. | ||||
| 1307 | if (comp_level > mh->highest_comp_level()) { | ||||
| 1308 | mh->set_highest_comp_level(comp_level); | ||||
| 1309 | } | ||||
| 1310 | |||||
| 1311 | OrderAccess::storestore(); | ||||
| 1312 | mh->_from_compiled_entry = code->verified_entry_point(); | ||||
| 1313 | OrderAccess::storestore(); | ||||
| 1314 | // Instantly compiled code can execute. | ||||
| 1315 | if (!mh->is_method_handle_intrinsic()) | ||||
| 1316 | mh->_from_interpreted_entry = mh->get_i2c_entry(); | ||||
| 1317 | } | ||||
| 1318 | |||||
| 1319 | |||||
| 1320 | bool Method::is_overridden_in(Klass* k) const { | ||||
| 1321 | InstanceKlass* ik = InstanceKlass::cast(k); | ||||
| 1322 | |||||
| 1323 | if (ik->is_interface()) return false; | ||||
| 1324 | |||||
| 1325 | // If method is an interface, we skip it - except if it | ||||
| 1326 | // is a miranda method | ||||
| 1327 | if (method_holder()->is_interface()) { | ||||
| 1328 | // Check that method is not a miranda method | ||||
| 1329 | if (ik->lookup_method(name(), signature()) == NULL__null) { | ||||
| 1330 | // No implementation exist - so miranda method | ||||
| 1331 | return false; | ||||
| 1332 | } | ||||
| 1333 | return true; | ||||
| 1334 | } | ||||
| 1335 | |||||
| 1336 | assert(ik->is_subclass_of(method_holder()), "should be subklass")do { if (!(ik->is_subclass_of(method_holder()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1336, "assert(" "ik->is_subclass_of(method_holder())" ") failed" , "should be subklass"); ::breakpoint(); } } while (0); | ||||
| 1337 | if (!has_vtable_index()) { | ||||
| 1338 | return false; | ||||
| 1339 | } else { | ||||
| 1340 | Method* vt_m = ik->method_at_vtable(vtable_index()); | ||||
| 1341 | return vt_m != this; | ||||
| 1342 | } | ||||
| 1343 | } | ||||
| 1344 | |||||
| 1345 | |||||
| 1346 | // give advice about whether this Method* should be cached or not | ||||
| 1347 | bool Method::should_not_be_cached() const { | ||||
| 1348 | if (is_old()) { | ||||
| 1349 | // This method has been redefined. It is either EMCP or obsolete | ||||
| 1350 | // and we don't want to cache it because that would pin the method | ||||
| 1351 | // down and prevent it from being collectible if and when it | ||||
| 1352 | // finishes executing. | ||||
| 1353 | return true; | ||||
| 1354 | } | ||||
| 1355 | |||||
| 1356 | // caching this method should be just fine | ||||
| 1357 | return false; | ||||
| 1358 | } | ||||
| 1359 | |||||
| 1360 | |||||
| 1361 | /** | ||||
| 1362 | * Returns true if this is one of the specially treated methods for | ||||
| 1363 | * security related stack walks (like Reflection.getCallerClass). | ||||
| 1364 | */ | ||||
| 1365 | bool Method::is_ignored_by_security_stack_walk() const { | ||||
| 1366 | if (intrinsic_id() == vmIntrinsics::_invoke) { | ||||
| 1367 | // This is Method.invoke() -- ignore it | ||||
| 1368 | return true; | ||||
| 1369 | } | ||||
| 1370 | if (method_holder()->is_subclass_of(vmClasses::reflect_MethodAccessorImpl_klass())) { | ||||
| 1371 | // This is an auxilary frame -- ignore it | ||||
| 1372 | return true; | ||||
| 1373 | } | ||||
| 1374 | if (is_method_handle_intrinsic() || is_compiled_lambda_form()) { | ||||
| 1375 | // This is an internal adapter frame for method handles -- ignore it | ||||
| 1376 | return true; | ||||
| 1377 | } | ||||
| 1378 | return false; | ||||
| 1379 | } | ||||
| 1380 | |||||
| 1381 | |||||
| 1382 | // Constant pool structure for invoke methods: | ||||
| 1383 | enum { | ||||
| 1384 | _imcp_invoke_name = 1, // utf8: 'invokeExact', etc. | ||||
| 1385 | _imcp_invoke_signature, // utf8: (variable Symbol*) | ||||
| 1386 | _imcp_limit | ||||
| 1387 | }; | ||||
| 1388 | |||||
| 1389 | // Test if this method is an MH adapter frame generated by Java code. | ||||
| 1390 | // Cf. java/lang/invoke/InvokerBytecodeGenerator | ||||
| 1391 | bool Method::is_compiled_lambda_form() const { | ||||
| 1392 | return intrinsic_id() == vmIntrinsics::_compiledLambdaForm; | ||||
| 1393 | } | ||||
| 1394 | |||||
| 1395 | // Test if this method is an internal MH primitive method. | ||||
| 1396 | bool Method::is_method_handle_intrinsic() const { | ||||
| 1397 | vmIntrinsics::ID iid = intrinsic_id(); | ||||
| 1398 | return (MethodHandles::is_signature_polymorphic(iid) && | ||||
| 1399 | MethodHandles::is_signature_polymorphic_intrinsic(iid)); | ||||
| 1400 | } | ||||
| 1401 | |||||
| 1402 | bool Method::has_member_arg() const { | ||||
| 1403 | vmIntrinsics::ID iid = intrinsic_id(); | ||||
| 1404 | return (MethodHandles::is_signature_polymorphic(iid) && | ||||
| 1405 | MethodHandles::has_member_arg(iid)); | ||||
| 1406 | } | ||||
| 1407 | |||||
| 1408 | // Make an instance of a signature-polymorphic internal MH primitive. | ||||
| 1409 | methodHandle Method::make_method_handle_intrinsic(vmIntrinsics::ID iid, | ||||
| 1410 | Symbol* signature, | ||||
| 1411 | TRAPSJavaThread* __the_thread__) { | ||||
| 1412 | ResourceMark rm(THREAD__the_thread__); | ||||
| 1413 | methodHandle empty; | ||||
| 1414 | |||||
| 1415 | InstanceKlass* holder = vmClasses::MethodHandle_klass(); | ||||
| 1416 | Symbol* name = MethodHandles::signature_polymorphic_intrinsic_name(iid); | ||||
| 1417 | assert(iid == MethodHandles::signature_polymorphic_name_id(name), "")do { if (!(iid == MethodHandles::signature_polymorphic_name_id (name))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1417, "assert(" "iid == MethodHandles::signature_polymorphic_name_id(name)" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 1418 | |||||
| 1419 | log_info(methodhandles)(!(LogImpl<(LogTag::_methodhandles), (LogTag::__NO_TAG), ( LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag ::__NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_methodhandles), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("make_method_handle_intrinsic MH.%s%s", name->as_C_string(), signature->as_C_string()); | ||||
| 1420 | |||||
| 1421 | // invariant: cp->symbol_at_put is preceded by a refcount increment (more usually a lookup) | ||||
| 1422 | name->increment_refcount(); | ||||
| 1423 | signature->increment_refcount(); | ||||
| 1424 | |||||
| 1425 | int cp_length = _imcp_limit; | ||||
| 1426 | ClassLoaderData* loader_data = holder->class_loader_data(); | ||||
| 1427 | constantPoolHandle cp; | ||||
| 1428 | { | ||||
| 1429 | ConstantPool* cp_oop = ConstantPool::allocate(loader_data, cp_length, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return empty; (void)(0); | ||||
| 1430 | cp = constantPoolHandle(THREAD__the_thread__, cp_oop); | ||||
| 1431 | } | ||||
| 1432 | cp->copy_fields(holder->constants()); | ||||
| 1433 | cp->set_pool_holder(holder); | ||||
| 1434 | cp->symbol_at_put(_imcp_invoke_name, name); | ||||
| 1435 | cp->symbol_at_put(_imcp_invoke_signature, signature); | ||||
| 1436 | cp->set_has_preresolution(); | ||||
| 1437 | |||||
| 1438 | // decide on access bits: public or not? | ||||
| 1439 | int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL); | ||||
| 1440 | bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid); | ||||
| 1441 | if (must_be_static) flags_bits |= JVM_ACC_STATIC; | ||||
| 1442 | assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods")do { if (!((flags_bits & JVM_ACC_PUBLIC) == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1442, "assert(" "(flags_bits & JVM_ACC_PUBLIC) == 0" ") failed" , "do not expose these methods"); ::breakpoint(); } } while ( 0); | ||||
| 1443 | |||||
| 1444 | methodHandle m; | ||||
| 1445 | { | ||||
| 1446 | InlineTableSizes sizes; | ||||
| 1447 | Method* m_oop = Method::allocate(loader_data, 0, | ||||
| 1448 | accessFlags_from(flags_bits), &sizes, | ||||
| 1449 | ConstMethod::NORMAL, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return empty; (void)(0); | ||||
| 1450 | m = methodHandle(THREAD__the_thread__, m_oop); | ||||
| 1451 | } | ||||
| 1452 | m->set_constants(cp()); | ||||
| 1453 | m->set_name_index(_imcp_invoke_name); | ||||
| 1454 | m->set_signature_index(_imcp_invoke_signature); | ||||
| 1455 | assert(MethodHandles::is_signature_polymorphic_name(m->name()), "")do { if (!(MethodHandles::is_signature_polymorphic_name(m-> name()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1455, "assert(" "MethodHandles::is_signature_polymorphic_name(m->name())" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 1456 | assert(m->signature() == signature, "")do { if (!(m->signature() == signature)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1456, "assert(" "m->signature() == signature" ") failed" , ""); ::breakpoint(); } } while (0); | ||||
| 1457 | m->compute_from_signature(signature); | ||||
| 1458 | m->init_intrinsic_id(klass_id_for_intrinsics(m->method_holder())); | ||||
| 1459 | assert(m->is_method_handle_intrinsic(), "")do { if (!(m->is_method_handle_intrinsic())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1459, "assert(" "m->is_method_handle_intrinsic()" ") failed" , ""); ::breakpoint(); } } while (0); | ||||
| 1460 | #ifdef ASSERT1 | ||||
| 1461 | if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print(); | ||||
| 1462 | assert(MethodHandles::is_signature_polymorphic(m->intrinsic_id()), "must be an invoker")do { if (!(MethodHandles::is_signature_polymorphic(m->intrinsic_id ()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1462, "assert(" "MethodHandles::is_signature_polymorphic(m->intrinsic_id())" ") failed", "must be an invoker"); ::breakpoint(); } } while (0); | ||||
| 1463 | assert(m->intrinsic_id() == iid, "correctly predicted iid")do { if (!(m->intrinsic_id() == iid)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1463, "assert(" "m->intrinsic_id() == iid" ") failed", "correctly predicted iid" ); ::breakpoint(); } } while (0); | ||||
| 1464 | #endif //ASSERT | ||||
| 1465 | |||||
| 1466 | // Finally, set up its entry points. | ||||
| 1467 | assert(m->can_be_statically_bound(), "")do { if (!(m->can_be_statically_bound())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1467, "assert(" "m->can_be_statically_bound()" ") failed" , ""); ::breakpoint(); } } while (0); | ||||
| 1468 | m->set_vtable_index(Method::nonvirtual_vtable_index); | ||||
| 1469 | m->link_method(m, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return empty; (void)(0); | ||||
| 1470 | |||||
| 1471 | if (iid == vmIntrinsics::_linkToNative) { | ||||
| 1472 | m->set_interpreter_entry(m->adapter()->get_i2c_entry()); | ||||
| 1473 | } | ||||
| 1474 | if (log_is_enabled(Info, methodhandles)(LogImpl<(LogTag::_methodhandles), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info)) && (Verbose || WizardMode)) { | ||||
| 1475 | LogTarget(Info, methodhandles)LogTargetImpl<LogLevel::Info, (LogTag::_methodhandles), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> lt; | ||||
| 1476 | LogStream ls(lt); | ||||
| 1477 | m->print_on(&ls); | ||||
| 1478 | } | ||||
| 1479 | |||||
| 1480 | return m; | ||||
| 1481 | } | ||||
| 1482 | |||||
| 1483 | Klass* Method::check_non_bcp_klass(Klass* klass) { | ||||
| 1484 | if (klass != NULL__null && klass->class_loader() != NULL__null) { | ||||
| 1485 | if (klass->is_objArray_klass()) | ||||
| 1486 | klass = ObjArrayKlass::cast(klass)->bottom_klass(); | ||||
| 1487 | return klass; | ||||
| 1488 | } | ||||
| 1489 | return NULL__null; | ||||
| 1490 | } | ||||
| 1491 | |||||
| 1492 | |||||
| 1493 | methodHandle Method::clone_with_new_data(const methodHandle& m, u_char* new_code, int new_code_length, | ||||
| 1494 | u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPSJavaThread* __the_thread__) { | ||||
| 1495 | // Code below does not work for native methods - they should never get rewritten anyway | ||||
| 1496 | assert(!m->is_native(), "cannot rewrite native methods")do { if (!(!m->is_native())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1496, "assert(" "!m->is_native()" ") failed", "cannot rewrite native methods" ); ::breakpoint(); } } while (0); | ||||
| 1497 | // Allocate new Method* | ||||
| 1498 | AccessFlags flags = m->access_flags(); | ||||
| 1499 | |||||
| 1500 | ConstMethod* cm = m->constMethod(); | ||||
| 1501 | int checked_exceptions_len = cm->checked_exceptions_length(); | ||||
| 1502 | int localvariable_len = cm->localvariable_table_length(); | ||||
| 1503 | int exception_table_len = cm->exception_table_length(); | ||||
| 1504 | int method_parameters_len = cm->method_parameters_length(); | ||||
| 1505 | int method_annotations_len = cm->method_annotations_length(); | ||||
| 1506 | int parameter_annotations_len = cm->parameter_annotations_length(); | ||||
| 1507 | int type_annotations_len = cm->type_annotations_length(); | ||||
| 1508 | int default_annotations_len = cm->default_annotations_length(); | ||||
| 1509 | |||||
| 1510 | InlineTableSizes sizes( | ||||
| 1511 | localvariable_len, | ||||
| 1512 | new_compressed_linenumber_size, | ||||
| 1513 | exception_table_len, | ||||
| 1514 | checked_exceptions_len, | ||||
| 1515 | method_parameters_len, | ||||
| 1516 | cm->generic_signature_index(), | ||||
| 1517 | method_annotations_len, | ||||
| 1518 | parameter_annotations_len, | ||||
| 1519 | type_annotations_len, | ||||
| 1520 | default_annotations_len, | ||||
| 1521 | 0); | ||||
| 1522 | |||||
| 1523 | ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); | ||||
| 1524 | Method* newm_oop = Method::allocate(loader_data, | ||||
| 1525 | new_code_length, | ||||
| 1526 | flags, | ||||
| 1527 | &sizes, | ||||
| 1528 | m->method_type(), | ||||
| 1529 | CHECK_(methodHandle())__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return methodHandle(); (void)(0); | ||||
| 1530 | methodHandle newm (THREAD__the_thread__, newm_oop); | ||||
| 1531 | |||||
| 1532 | // Create a shallow copy of Method part, but be careful to preserve the new ConstMethod* | ||||
| 1533 | ConstMethod* newcm = newm->constMethod(); | ||||
| 1534 | int new_const_method_size = newm->constMethod()->size(); | ||||
| 1535 | |||||
| 1536 | // This works because the source and target are both Methods. Some compilers | ||||
| 1537 | // (e.g., clang) complain that the target vtable pointer will be stomped, | ||||
| 1538 | // so cast away newm()'s and m()'s Methodness. | ||||
| 1539 | memcpy((void*)newm(), (void*)m(), sizeof(Method)); | ||||
| 1540 | |||||
| 1541 | // Create shallow copy of ConstMethod. | ||||
| 1542 | memcpy(newcm, m->constMethod(), sizeof(ConstMethod)); | ||||
| 1543 | |||||
| 1544 | // Reset correct method/const method, method size, and parameter info | ||||
| 1545 | newm->set_constMethod(newcm); | ||||
| 1546 | newm->constMethod()->set_code_size(new_code_length); | ||||
| 1547 | newm->constMethod()->set_constMethod_size(new_const_method_size); | ||||
| 1548 | assert(newm->code_size() == new_code_length, "check")do { if (!(newm->code_size() == new_code_length)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1548, "assert(" "newm->code_size() == new_code_length" ") failed" , "check"); ::breakpoint(); } } while (0); | ||||
| 1549 | assert(newm->method_parameters_length() == method_parameters_len, "check")do { if (!(newm->method_parameters_length() == method_parameters_len )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1549, "assert(" "newm->method_parameters_length() == method_parameters_len" ") failed", "check"); ::breakpoint(); } } while (0); | ||||
| 1550 | assert(newm->checked_exceptions_length() == checked_exceptions_len, "check")do { if (!(newm->checked_exceptions_length() == checked_exceptions_len )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1550, "assert(" "newm->checked_exceptions_length() == checked_exceptions_len" ") failed", "check"); ::breakpoint(); } } while (0); | ||||
| 1551 | assert(newm->exception_table_length() == exception_table_len, "check")do { if (!(newm->exception_table_length() == exception_table_len )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1551, "assert(" "newm->exception_table_length() == exception_table_len" ") failed", "check"); ::breakpoint(); } } while (0); | ||||
| 1552 | assert(newm->localvariable_table_length() == localvariable_len, "check")do { if (!(newm->localvariable_table_length() == localvariable_len )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1552, "assert(" "newm->localvariable_table_length() == localvariable_len" ") failed", "check"); ::breakpoint(); } } while (0); | ||||
| 1553 | // Copy new byte codes | ||||
| 1554 | memcpy(newm->code_base(), new_code, new_code_length); | ||||
| 1555 | // Copy line number table | ||||
| 1556 | if (new_compressed_linenumber_size > 0) { | ||||
| 1557 | memcpy(newm->compressed_linenumber_table(), | ||||
| 1558 | new_compressed_linenumber_table, | ||||
| 1559 | new_compressed_linenumber_size); | ||||
| 1560 | } | ||||
| 1561 | // Copy method_parameters | ||||
| 1562 | if (method_parameters_len > 0) { | ||||
| 1563 | memcpy(newm->method_parameters_start(), | ||||
| 1564 | m->method_parameters_start(), | ||||
| 1565 | method_parameters_len * sizeof(MethodParametersElement)); | ||||
| 1566 | } | ||||
| 1567 | // Copy checked_exceptions | ||||
| 1568 | if (checked_exceptions_len > 0) { | ||||
| 1569 | memcpy(newm->checked_exceptions_start(), | ||||
| 1570 | m->checked_exceptions_start(), | ||||
| 1571 | checked_exceptions_len * sizeof(CheckedExceptionElement)); | ||||
| 1572 | } | ||||
| 1573 | // Copy exception table | ||||
| 1574 | if (exception_table_len > 0) { | ||||
| 1575 | memcpy(newm->exception_table_start(), | ||||
| 1576 | m->exception_table_start(), | ||||
| 1577 | exception_table_len * sizeof(ExceptionTableElement)); | ||||
| 1578 | } | ||||
| 1579 | // Copy local variable number table | ||||
| 1580 | if (localvariable_len > 0) { | ||||
| 1581 | memcpy(newm->localvariable_table_start(), | ||||
| 1582 | m->localvariable_table_start(), | ||||
| 1583 | localvariable_len * sizeof(LocalVariableTableElement)); | ||||
| 1584 | } | ||||
| 1585 | // Copy stackmap table | ||||
| 1586 | if (m->has_stackmap_table()) { | ||||
| 1587 | int code_attribute_length = m->stackmap_data()->length(); | ||||
| 1588 | Array<u1>* stackmap_data = | ||||
| 1589 | MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_(methodHandle())__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return methodHandle(); (void)(0); | ||||
| 1590 | memcpy((void*)stackmap_data->adr_at(0), | ||||
| 1591 | (void*)m->stackmap_data()->adr_at(0), code_attribute_length); | ||||
| 1592 | newm->set_stackmap_data(stackmap_data); | ||||
| 1593 | } | ||||
| 1594 | |||||
| 1595 | // copy annotations over to new method | ||||
| 1596 | newcm->copy_annotations_from(loader_data, cm, CHECK_(methodHandle())__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return methodHandle(); (void)(0); | ||||
| 1597 | return newm; | ||||
| 1598 | } | ||||
| 1599 | |||||
| 1600 | vmSymbolID Method::klass_id_for_intrinsics(const Klass* holder) { | ||||
| 1601 | // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics | ||||
| 1602 | // because we are not loading from core libraries | ||||
| 1603 | // exception: the AES intrinsics come from lib/ext/sunjce_provider.jar | ||||
| 1604 | // which does not use the class default class loader so we check for its loader here | ||||
| 1605 | const InstanceKlass* ik = InstanceKlass::cast(holder); | ||||
| 1606 | if ((ik->class_loader() != NULL__null) && !SystemDictionary::is_platform_class_loader(ik->class_loader())) { | ||||
| 1607 | return vmSymbolID::NO_SID; // regardless of name, no intrinsics here | ||||
| 1608 | } | ||||
| 1609 | |||||
| 1610 | // see if the klass name is well-known: | ||||
| 1611 | Symbol* klass_name = ik->name(); | ||||
| 1612 | vmSymbolID id = vmSymbols::find_sid(klass_name); | ||||
| 1613 | if (id != vmSymbolID::NO_SID && vmIntrinsics::class_has_intrinsics(id)) { | ||||
| 1614 | return id; | ||||
| 1615 | } else { | ||||
| 1616 | return vmSymbolID::NO_SID; | ||||
| 1617 | } | ||||
| 1618 | } | ||||
| 1619 | |||||
| 1620 | void Method::init_intrinsic_id(vmSymbolID klass_id) { | ||||
| 1621 | assert(_intrinsic_id == static_cast<int>(vmIntrinsics::_none), "do this just once")do { if (!(_intrinsic_id == static_cast<int>(vmIntrinsics ::_none))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1621, "assert(" "_intrinsic_id == static_cast<int>(vmIntrinsics::_none)" ") failed", "do this just once"); ::breakpoint(); } } while ( 0); | ||||
| 1622 | const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte))(((((int)(sizeof(_intrinsic_id) * BitsPerByte)) >= BitsPerWord ) ? 0 : (OneBit << ((int)(sizeof(_intrinsic_id) * BitsPerByte )))) - 1); | ||||
| 1623 | assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size")do { if (!((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1623, "assert(" "(uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint" ") failed", "else fix size"); ::breakpoint(); } } while (0); | ||||
| 1624 | assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), "")do { if (!(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1624, "assert(" "intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id)" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 1625 | |||||
| 1626 | // the klass name is well-known: | ||||
| 1627 | assert(klass_id == klass_id_for_intrinsics(method_holder()), "must be")do { if (!(klass_id == klass_id_for_intrinsics(method_holder( )))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1627, "assert(" "klass_id == klass_id_for_intrinsics(method_holder())" ") failed", "must be"); ::breakpoint(); } } while (0); | ||||
| 1628 | assert(klass_id != vmSymbolID::NO_SID, "caller responsibility")do { if (!(klass_id != vmSymbolID::NO_SID)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1628, "assert(" "klass_id != vmSymbolID::NO_SID" ") failed" , "caller responsibility"); ::breakpoint(); } } while (0); | ||||
| 1629 | |||||
| 1630 | // ditto for method and signature: | ||||
| 1631 | vmSymbolID name_id = vmSymbols::find_sid(name()); | ||||
| 1632 | if (klass_id != VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle)vmSymbolID::java_lang_invoke_MethodHandle_enum | ||||
| 1633 | && klass_id != VM_SYMBOL_ENUM_NAME(java_lang_invoke_VarHandle)vmSymbolID::java_lang_invoke_VarHandle_enum | ||||
| 1634 | && name_id == vmSymbolID::NO_SID) { | ||||
| 1635 | return; | ||||
| 1636 | } | ||||
| 1637 | vmSymbolID sig_id = vmSymbols::find_sid(signature()); | ||||
| 1638 | if (klass_id != VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle)vmSymbolID::java_lang_invoke_MethodHandle_enum | ||||
| 1639 | && klass_id != VM_SYMBOL_ENUM_NAME(java_lang_invoke_VarHandle)vmSymbolID::java_lang_invoke_VarHandle_enum | ||||
| 1640 | && sig_id == vmSymbolID::NO_SID) { | ||||
| 1641 | return; | ||||
| 1642 | } | ||||
| 1643 | jshort flags = access_flags().as_short(); | ||||
| 1644 | |||||
| 1645 | vmIntrinsics::ID id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags); | ||||
| 1646 | if (id != vmIntrinsics::_none) { | ||||
| 1647 | set_intrinsic_id(id); | ||||
| 1648 | if (id == vmIntrinsics::_Class_cast) { | ||||
| 1649 | // Even if the intrinsic is rejected, we want to inline this simple method. | ||||
| 1650 | set_force_inline(true); | ||||
| 1651 | } | ||||
| 1652 | return; | ||||
| 1653 | } | ||||
| 1654 | |||||
| 1655 | // A few slightly irregular cases: | ||||
| 1656 | switch (klass_id) { | ||||
| 1657 | // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*., VarHandle | ||||
| 1658 | case VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle)vmSymbolID::java_lang_invoke_MethodHandle_enum: | ||||
| 1659 | case VM_SYMBOL_ENUM_NAME(java_lang_invoke_VarHandle)vmSymbolID::java_lang_invoke_VarHandle_enum: | ||||
| 1660 | if (!is_native()) break; | ||||
| 1661 | id = MethodHandles::signature_polymorphic_name_id(method_holder(), name()); | ||||
| 1662 | if (is_static() != MethodHandles::is_signature_polymorphic_static(id)) | ||||
| 1663 | id = vmIntrinsics::_none; | ||||
| 1664 | break; | ||||
| 1665 | |||||
| 1666 | default: | ||||
| 1667 | break; | ||||
| 1668 | } | ||||
| 1669 | |||||
| 1670 | if (id != vmIntrinsics::_none) { | ||||
| 1671 | // Set up its iid. It is an alias method. | ||||
| 1672 | set_intrinsic_id(id); | ||||
| 1673 | return; | ||||
| 1674 | } | ||||
| 1675 | } | ||||
| 1676 | |||||
| 1677 | bool Method::load_signature_classes(const methodHandle& m, TRAPSJavaThread* __the_thread__) { | ||||
| 1678 | if (!THREAD__the_thread__->can_call_java()) { | ||||
| 1679 | // There is nothing useful this routine can do from within the Compile thread. | ||||
| 1680 | // Hopefully, the signature contains only well-known classes. | ||||
| 1681 | // We could scan for this and return true/false, but the caller won't care. | ||||
| 1682 | return false; | ||||
| 1683 | } | ||||
| 1684 | bool sig_is_loaded = true; | ||||
| 1685 | ResourceMark rm(THREAD__the_thread__); | ||||
| 1686 | for (ResolvingSignatureStream ss(m()); !ss.is_done(); ss.next()) { | ||||
| 1687 | if (ss.is_reference()) { | ||||
| 1688 | // load everything, including arrays "[Lfoo;" | ||||
| 1689 | Klass* klass = ss.as_klass(SignatureStream::ReturnNull, THREAD__the_thread__); | ||||
| 1690 | // We are loading classes eagerly. If a ClassNotFoundException or | ||||
| 1691 | // a LinkageError was generated, be sure to ignore it. | ||||
| 1692 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | ||||
| 1693 | if (PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())->is_a(vmClasses::ClassNotFoundException_klass()) || | ||||
| 1694 | PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())->is_a(vmClasses::LinkageError_klass())) { | ||||
| 1695 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); | ||||
| 1696 | } else { | ||||
| 1697 | return false; | ||||
| 1698 | } | ||||
| 1699 | } | ||||
| 1700 | if( klass == NULL__null) { sig_is_loaded = false; } | ||||
| 1701 | } | ||||
| 1702 | } | ||||
| 1703 | return sig_is_loaded; | ||||
| 1704 | } | ||||
| 1705 | |||||
| 1706 | bool Method::has_unloaded_classes_in_signature(const methodHandle& m, TRAPSJavaThread* __the_thread__) { | ||||
| 1707 | ResourceMark rm(THREAD__the_thread__); | ||||
| 1708 | for(ResolvingSignatureStream ss(m()); !ss.is_done(); ss.next()) { | ||||
| 1709 | if (ss.type() == T_OBJECT) { | ||||
| 1710 | // Do not use ss.is_reference() here, since we don't care about | ||||
| 1711 | // unloaded array component types. | ||||
| 1712 | Klass* klass = ss.as_klass_if_loaded(THREAD__the_thread__); | ||||
| 1713 | assert(!HAS_PENDING_EXCEPTION, "as_klass_if_loaded contract")do { if (!(!(((ThreadShadow*)__the_thread__)->has_pending_exception ()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1713, "assert(" "!(((ThreadShadow*)__the_thread__)->has_pending_exception())" ") failed", "as_klass_if_loaded contract"); ::breakpoint(); } } while (0); | ||||
| 1714 | if (klass == NULL__null) return true; | ||||
| 1715 | } | ||||
| 1716 | } | ||||
| 1717 | return false; | ||||
| 1718 | } | ||||
| 1719 | |||||
| 1720 | // Exposed so field engineers can debug VM | ||||
| 1721 | void Method::print_short_name(outputStream* st) { | ||||
| 1722 | ResourceMark rm; | ||||
| 1723 | #ifdef PRODUCT | ||||
| 1724 | st->print(" %s::", method_holder()->external_name()); | ||||
| 1725 | #else | ||||
| 1726 | st->print(" %s::", method_holder()->internal_name()); | ||||
| 1727 | #endif | ||||
| 1728 | name()->print_symbol_on(st); | ||||
| 1729 | if (WizardMode) signature()->print_symbol_on(st); | ||||
| 1730 | else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) | ||||
| 1731 | MethodHandles::print_as_basic_type_signature_on(st, signature()); | ||||
| 1732 | } | ||||
| 1733 | |||||
| 1734 | // Comparer for sorting an object array containing | ||||
| 1735 | // Method*s. | ||||
| 1736 | static int method_comparator(Method* a, Method* b) { | ||||
| 1737 | return a->name()->fast_compare(b->name()); | ||||
| 1738 | } | ||||
| 1739 | |||||
| 1740 | // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array | ||||
| 1741 | // default_methods also uses this without the ordering for fast find_method | ||||
| 1742 | void Method::sort_methods(Array<Method*>* methods, bool set_idnums, method_comparator_func func) { | ||||
| 1743 | int length = methods->length(); | ||||
| 1744 | if (length > 1) { | ||||
| 1745 | if (func == NULL__null) { | ||||
| 1746 | func = method_comparator; | ||||
| 1747 | } | ||||
| 1748 | { | ||||
| 1749 | NoSafepointVerifier nsv; | ||||
| 1750 | QuickSort::sort(methods->data(), length, func, /*idempotent=*/false); | ||||
| 1751 | } | ||||
| 1752 | // Reset method ordering | ||||
| 1753 | if (set_idnums) { | ||||
| 1754 | for (int i = 0; i < length; i++) { | ||||
| 1755 | Method* m = methods->at(i); | ||||
| 1756 | m->set_method_idnum(i); | ||||
| 1757 | m->set_orig_method_idnum(i); | ||||
| 1758 | } | ||||
| 1759 | } | ||||
| 1760 | } | ||||
| 1761 | } | ||||
| 1762 | |||||
| 1763 | //----------------------------------------------------------------------------------- | ||||
| 1764 | // Non-product code unless JVM/TI needs it | ||||
| 1765 | |||||
| 1766 | #if !defined(PRODUCT) || INCLUDE_JVMTI1 | ||||
| 1767 | class SignatureTypePrinter : public SignatureTypeNames { | ||||
| 1768 | private: | ||||
| 1769 | outputStream* _st; | ||||
| 1770 | bool _use_separator; | ||||
| 1771 | |||||
| 1772 | void type_name(const char* name) { | ||||
| 1773 | if (_use_separator) _st->print(", "); | ||||
| 1774 | _st->print("%s", name); | ||||
| 1775 | _use_separator = true; | ||||
| 1776 | } | ||||
| 1777 | |||||
| 1778 | public: | ||||
| 1779 | SignatureTypePrinter(Symbol* signature, outputStream* st) : SignatureTypeNames(signature) { | ||||
| 1780 | _st = st; | ||||
| 1781 | _use_separator = false; | ||||
| 1782 | } | ||||
| 1783 | |||||
| 1784 | void print_parameters() { _use_separator = false; do_parameters_on(this); } | ||||
| 1785 | void print_returntype() { _use_separator = false; do_type(return_type()); } | ||||
| 1786 | }; | ||||
| 1787 | |||||
| 1788 | |||||
| 1789 | void Method::print_name(outputStream* st) { | ||||
| 1790 | Thread *thread = Thread::current(); | ||||
| 1791 | ResourceMark rm(thread); | ||||
| 1792 | st->print("%s ", is_static() ? "static" : "virtual"); | ||||
| 1793 | if (WizardMode) { | ||||
| 1794 | st->print("%s.", method_holder()->internal_name()); | ||||
| 1795 | name()->print_symbol_on(st); | ||||
| 1796 | signature()->print_symbol_on(st); | ||||
| 1797 | } else { | ||||
| 1798 | SignatureTypePrinter sig(signature(), st); | ||||
| 1799 | sig.print_returntype(); | ||||
| 1800 | st->print(" %s.", method_holder()->internal_name()); | ||||
| 1801 | name()->print_symbol_on(st); | ||||
| 1802 | st->print("("); | ||||
| 1803 | sig.print_parameters(); | ||||
| 1804 | st->print(")"); | ||||
| 1805 | } | ||||
| 1806 | } | ||||
| 1807 | #endif // !PRODUCT || INCLUDE_JVMTI | ||||
| 1808 | |||||
| 1809 | |||||
| 1810 | void Method::print_codes_on(outputStream* st) const { | ||||
| 1811 | print_codes_on(0, code_size(), st); | ||||
| 1812 | } | ||||
| 1813 | |||||
| 1814 | void Method::print_codes_on(int from, int to, outputStream* st) const { | ||||
| 1815 | Thread *thread = Thread::current(); | ||||
| 1816 | ResourceMark rm(thread); | ||||
| 1817 | methodHandle mh (thread, (Method*)this); | ||||
| 1818 | BytecodeStream s(mh); | ||||
| 1819 | s.set_interval(from, to); | ||||
| 1820 | BytecodeTracer::set_closure(BytecodeTracer::std_closure()); | ||||
| 1821 | while (s.next() >= 0) BytecodeTracer::trace(mh, s.bcp(), st); | ||||
| 1822 | } | ||||
| 1823 | |||||
| 1824 | CompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) { | ||||
| 1825 | _bci = 0; | ||||
| 1826 | _line = 0; | ||||
| 1827 | }; | ||||
| 1828 | |||||
| 1829 | bool CompressedLineNumberReadStream::read_pair() { | ||||
| 1830 | jubyte next = read_byte(); | ||||
| 1831 | // Check for terminator | ||||
| 1832 | if (next == 0) return false; | ||||
| 1833 | if (next == 0xFF) { | ||||
| 1834 | // Escape character, regular compression used | ||||
| 1835 | _bci += read_signed_int(); | ||||
| 1836 | _line += read_signed_int(); | ||||
| 1837 | } else { | ||||
| 1838 | // Single byte compression used | ||||
| 1839 | _bci += next >> 3; | ||||
| 1840 | _line += next & 0x7; | ||||
| 1841 | } | ||||
| 1842 | return true; | ||||
| 1843 | } | ||||
| 1844 | |||||
| 1845 | #if INCLUDE_JVMTI1 | ||||
| 1846 | |||||
| 1847 | Bytecodes::Code Method::orig_bytecode_at(int bci) const { | ||||
| 1848 | BreakpointInfo* bp = method_holder()->breakpoints(); | ||||
| 1849 | for (; bp != NULL__null; bp = bp->next()) { | ||||
| 1850 | if (bp->match(this, bci)) { | ||||
| 1851 | return bp->orig_bytecode(); | ||||
| 1852 | } | ||||
| 1853 | } | ||||
| 1854 | { | ||||
| 1855 | ResourceMark rm; | ||||
| 1856 | fatal("no original bytecode found in %s at bci %d", name_and_sig_as_C_string(), bci)do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1856, "no original bytecode found in %s at bci %d", name_and_sig_as_C_string (), bci); ::breakpoint(); } while (0); | ||||
| 1857 | } | ||||
| 1858 | return Bytecodes::_shouldnotreachhere; | ||||
| 1859 | } | ||||
| 1860 | |||||
| 1861 | void Method::set_orig_bytecode_at(int bci, Bytecodes::Code code) { | ||||
| 1862 | assert(code != Bytecodes::_breakpoint, "cannot patch breakpoints this way")do { if (!(code != Bytecodes::_breakpoint)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1862, "assert(" "code != Bytecodes::_breakpoint" ") failed" , "cannot patch breakpoints this way"); ::breakpoint(); } } while (0); | ||||
| 1863 | BreakpointInfo* bp = method_holder()->breakpoints(); | ||||
| 1864 | for (; bp != NULL__null; bp = bp->next()) { | ||||
| 1865 | if (bp->match(this, bci)) { | ||||
| 1866 | bp->set_orig_bytecode(code); | ||||
| 1867 | // and continue, in case there is more than one | ||||
| 1868 | } | ||||
| 1869 | } | ||||
| 1870 | } | ||||
| 1871 | |||||
| 1872 | void Method::set_breakpoint(int bci) { | ||||
| 1873 | InstanceKlass* ik = method_holder(); | ||||
| 1874 | BreakpointInfo *bp = new BreakpointInfo(this, bci); | ||||
| 1875 | bp->set_next(ik->breakpoints()); | ||||
| 1876 | ik->set_breakpoints(bp); | ||||
| 1877 | // do this last: | ||||
| 1878 | bp->set(this); | ||||
| 1879 | } | ||||
| 1880 | |||||
| 1881 | static void clear_matches(Method* m, int bci) { | ||||
| 1882 | InstanceKlass* ik = m->method_holder(); | ||||
| 1883 | BreakpointInfo* prev_bp = NULL__null; | ||||
| 1884 | BreakpointInfo* next_bp; | ||||
| 1885 | for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL__null; bp = next_bp) { | ||||
| 1886 | next_bp = bp->next(); | ||||
| 1887 | // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint). | ||||
| 1888 | if (bci >= 0 ? bp->match(m, bci) : bp->match(m)) { | ||||
| 1889 | // do this first: | ||||
| 1890 | bp->clear(m); | ||||
| 1891 | // unhook it | ||||
| 1892 | if (prev_bp != NULL__null) | ||||
| 1893 | prev_bp->set_next(next_bp); | ||||
| 1894 | else | ||||
| 1895 | ik->set_breakpoints(next_bp); | ||||
| 1896 | delete bp; | ||||
| 1897 | // When class is redefined JVMTI sets breakpoint in all versions of EMCP methods | ||||
| 1898 | // at same location. So we have multiple matching (method_index and bci) | ||||
| 1899 | // BreakpointInfo nodes in BreakpointInfo list. We should just delete one | ||||
| 1900 | // breakpoint for clear_breakpoint request and keep all other method versions | ||||
| 1901 | // BreakpointInfo for future clear_breakpoint request. | ||||
| 1902 | // bcivalue of -1 is used to clear all breakpoints (see clear_all_breakpoints) | ||||
| 1903 | // which is being called when class is unloaded. We delete all the Breakpoint | ||||
| 1904 | // information for all versions of method. We may not correctly restore the original | ||||
| 1905 | // bytecode in all method versions, but that is ok. Because the class is being unloaded | ||||
| 1906 | // so these methods won't be used anymore. | ||||
| 1907 | if (bci >= 0) { | ||||
| 1908 | break; | ||||
| 1909 | } | ||||
| 1910 | } else { | ||||
| 1911 | // This one is a keeper. | ||||
| 1912 | prev_bp = bp; | ||||
| 1913 | } | ||||
| 1914 | } | ||||
| 1915 | } | ||||
| 1916 | |||||
| 1917 | void Method::clear_breakpoint(int bci) { | ||||
| 1918 | assert(bci >= 0, "")do { if (!(bci >= 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 1918, "assert(" "bci >= 0" ") failed", ""); ::breakpoint (); } } while (0); | ||||
| 1919 | clear_matches(this, bci); | ||||
| 1920 | } | ||||
| 1921 | |||||
| 1922 | void Method::clear_all_breakpoints() { | ||||
| 1923 | clear_matches(this, -1); | ||||
| 1924 | } | ||||
| 1925 | |||||
| 1926 | #endif // INCLUDE_JVMTI | ||||
| 1927 | |||||
| 1928 | int Method::invocation_count() const { | ||||
| 1929 | MethodCounters* mcs = method_counters(); | ||||
| 1930 | MethodData* mdo = method_data(); | ||||
| 1931 | if (((mcs != NULL__null) ? mcs->invocation_counter()->carry() : false) || | ||||
| 1932 | ((mdo != NULL__null) ? mdo->invocation_counter()->carry() : false)) { | ||||
| 1933 | return InvocationCounter::count_limit; | ||||
| 1934 | } else { | ||||
| 1935 | return ((mcs != NULL__null) ? mcs->invocation_counter()->count() : 0) + | ||||
| 1936 | ((mdo != NULL__null) ? mdo->invocation_counter()->count() : 0); | ||||
| 1937 | } | ||||
| 1938 | } | ||||
| 1939 | |||||
| 1940 | int Method::backedge_count() const { | ||||
| 1941 | MethodCounters* mcs = method_counters(); | ||||
| 1942 | MethodData* mdo = method_data(); | ||||
| 1943 | if (((mcs != NULL__null) ? mcs->backedge_counter()->carry() : false) || | ||||
| 1944 | ((mdo != NULL__null) ? mdo->backedge_counter()->carry() : false)) { | ||||
| 1945 | return InvocationCounter::count_limit; | ||||
| 1946 | } else { | ||||
| 1947 | return ((mcs != NULL__null) ? mcs->backedge_counter()->count() : 0) + | ||||
| 1948 | ((mdo != NULL__null) ? mdo->backedge_counter()->count() : 0); | ||||
| 1949 | } | ||||
| 1950 | } | ||||
| 1951 | |||||
| 1952 | int Method::highest_comp_level() const { | ||||
| 1953 | const MethodCounters* mcs = method_counters(); | ||||
| 1954 | if (mcs != NULL__null) { | ||||
| 1955 | return mcs->highest_comp_level(); | ||||
| 1956 | } else { | ||||
| 1957 | return CompLevel_none; | ||||
| 1958 | } | ||||
| 1959 | } | ||||
| 1960 | |||||
| 1961 | int Method::highest_osr_comp_level() const { | ||||
| 1962 | const MethodCounters* mcs = method_counters(); | ||||
| 1963 | if (mcs != NULL__null) { | ||||
| 1964 | return mcs->highest_osr_comp_level(); | ||||
| 1965 | } else { | ||||
| 1966 | return CompLevel_none; | ||||
| 1967 | } | ||||
| 1968 | } | ||||
| 1969 | |||||
| 1970 | void Method::set_highest_comp_level(int level) { | ||||
| 1971 | MethodCounters* mcs = method_counters(); | ||||
| 1972 | if (mcs != NULL__null) { | ||||
| 1973 | mcs->set_highest_comp_level(level); | ||||
| 1974 | } | ||||
| 1975 | } | ||||
| 1976 | |||||
| 1977 | void Method::set_highest_osr_comp_level(int level) { | ||||
| 1978 | MethodCounters* mcs = method_counters(); | ||||
| 1979 | if (mcs != NULL__null) { | ||||
| 1980 | mcs->set_highest_osr_comp_level(level); | ||||
| 1981 | } | ||||
| 1982 | } | ||||
| 1983 | |||||
| 1984 | #if INCLUDE_JVMTI1 | ||||
| 1985 | |||||
| 1986 | BreakpointInfo::BreakpointInfo(Method* m, int bci) { | ||||
| 1987 | _bci = bci; | ||||
| 1988 | _name_index = m->name_index(); | ||||
| 1989 | _signature_index = m->signature_index(); | ||||
| 1990 | _orig_bytecode = (Bytecodes::Code) *m->bcp_from(_bci); | ||||
| 1991 | if (_orig_bytecode == Bytecodes::_breakpoint) | ||||
| 1992 | _orig_bytecode = m->orig_bytecode_at(_bci); | ||||
| 1993 | _next = NULL__null; | ||||
| 1994 | } | ||||
| 1995 | |||||
| 1996 | void BreakpointInfo::set(Method* method) { | ||||
| 1997 | #ifdef ASSERT1 | ||||
| 1998 | { | ||||
| 1999 | Bytecodes::Code code = (Bytecodes::Code) *method->bcp_from(_bci); | ||||
| 2000 | if (code == Bytecodes::_breakpoint) | ||||
| 2001 | code = method->orig_bytecode_at(_bci); | ||||
| 2002 | assert(orig_bytecode() == code, "original bytecode must be the same")do { if (!(orig_bytecode() == code)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2002, "assert(" "orig_bytecode() == code" ") failed", "original bytecode must be the same" ); ::breakpoint(); } } while (0); | ||||
| 2003 | } | ||||
| 2004 | #endif | ||||
| 2005 | Thread *thread = Thread::current(); | ||||
| 2006 | *method->bcp_from(_bci) = Bytecodes::_breakpoint; | ||||
| 2007 | method->incr_number_of_breakpoints(thread); | ||||
| 2008 | { | ||||
| 2009 | // Deoptimize all dependents on this method | ||||
| 2010 | HandleMark hm(thread); | ||||
| 2011 | methodHandle mh(thread, method); | ||||
| 2012 | CodeCache::flush_dependents_on_method(mh); | ||||
| 2013 | } | ||||
| 2014 | } | ||||
| 2015 | |||||
| 2016 | void BreakpointInfo::clear(Method* method) { | ||||
| 2017 | *method->bcp_from(_bci) = orig_bytecode(); | ||||
| 2018 | assert(method->number_of_breakpoints() > 0, "must not go negative")do { if (!(method->number_of_breakpoints() > 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2018, "assert(" "method->number_of_breakpoints() > 0" ") failed", "must not go negative"); ::breakpoint(); } } while (0); | ||||
| 2019 | method->decr_number_of_breakpoints(Thread::current()); | ||||
| 2020 | } | ||||
| 2021 | |||||
| 2022 | #endif // INCLUDE_JVMTI | ||||
| 2023 | |||||
| 2024 | // jmethodID handling | ||||
| 2025 | |||||
| 2026 | // This is a block allocating object, sort of like JNIHandleBlock, only a | ||||
| 2027 | // lot simpler. | ||||
| 2028 | // It's allocated on the CHeap because once we allocate a jmethodID, we can | ||||
| 2029 | // never get rid of it. | ||||
| 2030 | |||||
| 2031 | static const int min_block_size = 8; | ||||
| 2032 | |||||
| 2033 | class JNIMethodBlockNode : public CHeapObj<mtClass> { | ||||
| 2034 | friend class JNIMethodBlock; | ||||
| 2035 | Method** _methods; | ||||
| 2036 | int _number_of_methods; | ||||
| 2037 | int _top; | ||||
| 2038 | JNIMethodBlockNode* _next; | ||||
| 2039 | |||||
| 2040 | public: | ||||
| 2041 | |||||
| 2042 | JNIMethodBlockNode(int num_methods = min_block_size); | ||||
| 2043 | |||||
| 2044 | ~JNIMethodBlockNode() { FREE_C_HEAP_ARRAY(Method*, _methods)FreeHeap((char*)(_methods)); } | ||||
| 2045 | |||||
| 2046 | void ensure_methods(int num_addl_methods) { | ||||
| 2047 | if (_top < _number_of_methods) { | ||||
| 2048 | num_addl_methods -= _number_of_methods - _top; | ||||
| 2049 | if (num_addl_methods <= 0) { | ||||
| 2050 | return; | ||||
| 2051 | } | ||||
| 2052 | } | ||||
| 2053 | if (_next == NULL__null) { | ||||
| 2054 | _next = new JNIMethodBlockNode(MAX2(num_addl_methods, min_block_size)); | ||||
| 2055 | } else { | ||||
| 2056 | _next->ensure_methods(num_addl_methods); | ||||
| 2057 | } | ||||
| 2058 | } | ||||
| 2059 | }; | ||||
| 2060 | |||||
| 2061 | class JNIMethodBlock : public CHeapObj<mtClass> { | ||||
| 2062 | JNIMethodBlockNode _head; | ||||
| 2063 | JNIMethodBlockNode *_last_free; | ||||
| 2064 | public: | ||||
| 2065 | static Method* const _free_method; | ||||
| 2066 | |||||
| 2067 | JNIMethodBlock(int initial_capacity = min_block_size) | ||||
| 2068 | : _head(initial_capacity), _last_free(&_head) {} | ||||
| 2069 | |||||
| 2070 | void ensure_methods(int num_addl_methods) { | ||||
| 2071 | _last_free->ensure_methods(num_addl_methods); | ||||
| 2072 | } | ||||
| 2073 | |||||
| 2074 | Method** add_method(Method* m) { | ||||
| 2075 | for (JNIMethodBlockNode* b = _last_free; b != NULL__null; b = b->_next) { | ||||
| 2076 | if (b->_top < b->_number_of_methods) { | ||||
| 2077 | // top points to the next free entry. | ||||
| 2078 | int i = b->_top; | ||||
| 2079 | b->_methods[i] = m; | ||||
| 2080 | b->_top++; | ||||
| 2081 | _last_free = b; | ||||
| 2082 | return &(b->_methods[i]); | ||||
| 2083 | } else if (b->_top == b->_number_of_methods) { | ||||
| 2084 | // if the next free entry ran off the block see if there's a free entry | ||||
| 2085 | for (int i = 0; i < b->_number_of_methods; i++) { | ||||
| 2086 | if (b->_methods[i] == _free_method) { | ||||
| 2087 | b->_methods[i] = m; | ||||
| 2088 | _last_free = b; | ||||
| 2089 | return &(b->_methods[i]); | ||||
| 2090 | } | ||||
| 2091 | } | ||||
| 2092 | // Only check each block once for frees. They're very unlikely. | ||||
| 2093 | // Increment top past the end of the block. | ||||
| 2094 | b->_top++; | ||||
| 2095 | } | ||||
| 2096 | // need to allocate a next block. | ||||
| 2097 | if (b->_next == NULL__null) { | ||||
| 2098 | b->_next = _last_free = new JNIMethodBlockNode(); | ||||
| 2099 | } | ||||
| 2100 | } | ||||
| 2101 | guarantee(false, "Should always allocate a free block")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2101, "guarantee(" "false" ") failed", "Should always allocate a free block" ); ::breakpoint(); } } while (0); | ||||
| 2102 | return NULL__null; | ||||
| 2103 | } | ||||
| 2104 | |||||
| 2105 | bool contains(Method** m) { | ||||
| 2106 | if (m == NULL__null) return false; | ||||
| 2107 | for (JNIMethodBlockNode* b = &_head; b != NULL__null; b = b->_next) { | ||||
| 2108 | if (b->_methods <= m && m < b->_methods + b->_number_of_methods) { | ||||
| 2109 | // This is a bit of extra checking, for two reasons. One is | ||||
| 2110 | // that contains() deals with pointers that are passed in by | ||||
| 2111 | // JNI code, so making sure that the pointer is aligned | ||||
| 2112 | // correctly is valuable. The other is that <= and > are | ||||
| 2113 | // technically not defined on pointers, so the if guard can | ||||
| 2114 | // pass spuriously; no modern compiler is likely to make that | ||||
| 2115 | // a problem, though (and if one did, the guard could also | ||||
| 2116 | // fail spuriously, which would be bad). | ||||
| 2117 | ptrdiff_t idx = m - b->_methods; | ||||
| 2118 | if (b->_methods + idx == m) { | ||||
| 2119 | return true; | ||||
| 2120 | } | ||||
| 2121 | } | ||||
| 2122 | } | ||||
| 2123 | return false; // not found | ||||
| 2124 | } | ||||
| 2125 | |||||
| 2126 | // Doesn't really destroy it, just marks it as free so it can be reused. | ||||
| 2127 | void destroy_method(Method** m) { | ||||
| 2128 | #ifdef ASSERT1 | ||||
| 2129 | assert(contains(m), "should be a methodID")do { if (!(contains(m))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2129, "assert(" "contains(m)" ") failed", "should be a methodID" ); ::breakpoint(); } } while (0); | ||||
| 2130 | #endif // ASSERT | ||||
| 2131 | *m = _free_method; | ||||
| 2132 | } | ||||
| 2133 | |||||
| 2134 | // During class unloading the methods are cleared, which is different | ||||
| 2135 | // than freed. | ||||
| 2136 | void clear_all_methods() { | ||||
| 2137 | for (JNIMethodBlockNode* b = &_head; b != NULL__null; b = b->_next) { | ||||
| 2138 | for (int i = 0; i< b->_number_of_methods; i++) { | ||||
| 2139 | b->_methods[i] = NULL__null; | ||||
| 2140 | } | ||||
| 2141 | } | ||||
| 2142 | } | ||||
| 2143 | #ifndef PRODUCT | ||||
| 2144 | int count_methods() { | ||||
| 2145 | // count all allocated methods | ||||
| 2146 | int count = 0; | ||||
| 2147 | for (JNIMethodBlockNode* b = &_head; b != NULL__null; b = b->_next) { | ||||
| 2148 | for (int i = 0; i< b->_number_of_methods; i++) { | ||||
| 2149 | if (b->_methods[i] != _free_method) count++; | ||||
| 2150 | } | ||||
| 2151 | } | ||||
| 2152 | return count; | ||||
| 2153 | } | ||||
| 2154 | #endif // PRODUCT | ||||
| 2155 | }; | ||||
| 2156 | |||||
| 2157 | // Something that can't be mistaken for an address or a markWord | ||||
| 2158 | Method* const JNIMethodBlock::_free_method = (Method*)55; | ||||
| 2159 | |||||
| 2160 | JNIMethodBlockNode::JNIMethodBlockNode(int num_methods) : _top(0), _next(NULL__null) { | ||||
| 2161 | _number_of_methods = MAX2(num_methods, min_block_size); | ||||
| 2162 | _methods = NEW_C_HEAP_ARRAY(Method*, _number_of_methods, mtInternal)(Method**) (AllocateHeap((_number_of_methods) * sizeof(Method *), mtInternal)); | ||||
| 2163 | for (int i = 0; i < _number_of_methods; i++) { | ||||
| 2164 | _methods[i] = JNIMethodBlock::_free_method; | ||||
| 2165 | } | ||||
| 2166 | } | ||||
| 2167 | |||||
| 2168 | void Method::ensure_jmethod_ids(ClassLoaderData* loader_data, int capacity) { | ||||
| 2169 | ClassLoaderData* cld = loader_data; | ||||
| 2170 | if (!SafepointSynchronize::is_at_safepoint()) { | ||||
| 2171 | // Have to add jmethod_ids() to class loader data thread-safely. | ||||
| 2172 | // Also have to add the method to the list safely, which the lock | ||||
| 2173 | // protects as well. | ||||
| 2174 | MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag); | ||||
| 2175 | if (cld->jmethod_ids() == NULL__null) { | ||||
| 2176 | cld->set_jmethod_ids(new JNIMethodBlock(capacity)); | ||||
| 2177 | } else { | ||||
| 2178 | cld->jmethod_ids()->ensure_methods(capacity); | ||||
| 2179 | } | ||||
| 2180 | } else { | ||||
| 2181 | // At safepoint, we are single threaded and can set this. | ||||
| 2182 | if (cld->jmethod_ids() == NULL__null) { | ||||
| 2183 | cld->set_jmethod_ids(new JNIMethodBlock(capacity)); | ||||
| 2184 | } else { | ||||
| 2185 | cld->jmethod_ids()->ensure_methods(capacity); | ||||
| 2186 | } | ||||
| 2187 | } | ||||
| 2188 | } | ||||
| 2189 | |||||
| 2190 | // Add a method id to the jmethod_ids | ||||
| 2191 | jmethodID Method::make_jmethod_id(ClassLoaderData* loader_data, Method* m) { | ||||
| 2192 | ClassLoaderData* cld = loader_data; | ||||
| 2193 | |||||
| 2194 | if (!SafepointSynchronize::is_at_safepoint()) { | ||||
| 2195 | // Have to add jmethod_ids() to class loader data thread-safely. | ||||
| 2196 | // Also have to add the method to the list safely, which the lock | ||||
| 2197 | // protects as well. | ||||
| 2198 | MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag); | ||||
| 2199 | if (cld->jmethod_ids() == NULL__null) { | ||||
| 2200 | cld->set_jmethod_ids(new JNIMethodBlock()); | ||||
| 2201 | } | ||||
| 2202 | // jmethodID is a pointer to Method* | ||||
| 2203 | return (jmethodID)cld->jmethod_ids()->add_method(m); | ||||
| 2204 | } else { | ||||
| 2205 | // At safepoint, we are single threaded and can set this. | ||||
| 2206 | if (cld->jmethod_ids() == NULL__null) { | ||||
| 2207 | cld->set_jmethod_ids(new JNIMethodBlock()); | ||||
| 2208 | } | ||||
| 2209 | // jmethodID is a pointer to Method* | ||||
| 2210 | return (jmethodID)cld->jmethod_ids()->add_method(m); | ||||
| 2211 | } | ||||
| 2212 | } | ||||
| 2213 | |||||
| 2214 | jmethodID Method::jmethod_id() { | ||||
| 2215 | methodHandle mh(Thread::current(), this); | ||||
| 2216 | return method_holder()->get_jmethod_id(mh); | ||||
| 2217 | } | ||||
| 2218 | |||||
| 2219 | // Mark a jmethodID as free. This is called when there is a data race in | ||||
| 2220 | // InstanceKlass while creating the jmethodID cache. | ||||
| 2221 | void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) { | ||||
| 2222 | ClassLoaderData* cld = loader_data; | ||||
| 2223 | Method** ptr = (Method**)m; | ||||
| 2224 | assert(cld->jmethod_ids() != NULL, "should have method handles")do { if (!(cld->jmethod_ids() != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2224, "assert(" "cld->jmethod_ids() != __null" ") failed" , "should have method handles"); ::breakpoint(); } } while (0 ); | ||||
| 2225 | cld->jmethod_ids()->destroy_method(ptr); | ||||
| 2226 | } | ||||
| 2227 | |||||
| 2228 | void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) { | ||||
| 2229 | // Can't assert the method_holder is the same because the new method has the | ||||
| 2230 | // scratch method holder. | ||||
| 2231 | assert(resolve_jmethod_id(jmid)->method_holder()->class_loader()do { if (!(resolve_jmethod_id(jmid)->method_holder()->class_loader () == new_method->method_holder()->class_loader() || new_method ->method_holder()->class_loader() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2234, "assert(" "resolve_jmethod_id(jmid)->method_holder()->class_loader() == new_method->method_holder()->class_loader() || new_method->method_holder()->class_loader() == __null" ") failed", "changing to a different class loader"); ::breakpoint (); } } while (0) | ||||
| 2232 | == new_method->method_holder()->class_loader() ||do { if (!(resolve_jmethod_id(jmid)->method_holder()->class_loader () == new_method->method_holder()->class_loader() || new_method ->method_holder()->class_loader() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2234, "assert(" "resolve_jmethod_id(jmid)->method_holder()->class_loader() == new_method->method_holder()->class_loader() || new_method->method_holder()->class_loader() == __null" ") failed", "changing to a different class loader"); ::breakpoint (); } } while (0) | ||||
| 2233 | new_method->method_holder()->class_loader() == NULL, // allow Unsafe substitutiondo { if (!(resolve_jmethod_id(jmid)->method_holder()->class_loader () == new_method->method_holder()->class_loader() || new_method ->method_holder()->class_loader() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2234, "assert(" "resolve_jmethod_id(jmid)->method_holder()->class_loader() == new_method->method_holder()->class_loader() || new_method->method_holder()->class_loader() == __null" ") failed", "changing to a different class loader"); ::breakpoint (); } } while (0) | ||||
| 2234 | "changing to a different class loader")do { if (!(resolve_jmethod_id(jmid)->method_holder()->class_loader () == new_method->method_holder()->class_loader() || new_method ->method_holder()->class_loader() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2234, "assert(" "resolve_jmethod_id(jmid)->method_holder()->class_loader() == new_method->method_holder()->class_loader() || new_method->method_holder()->class_loader() == __null" ") failed", "changing to a different class loader"); ::breakpoint (); } } while (0); | ||||
| 2235 | // Just change the method in place, jmethodID pointer doesn't change. | ||||
| 2236 | *((Method**)jmid) = new_method; | ||||
| 2237 | } | ||||
| 2238 | |||||
| 2239 | bool Method::is_method_id(jmethodID mid) { | ||||
| 2240 | Method* m = resolve_jmethod_id(mid); | ||||
| 2241 | assert(m != NULL, "should be called with non-null method")do { if (!(m != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2241, "assert(" "m != __null" ") failed", "should be called with non-null method" ); ::breakpoint(); } } while (0); | ||||
| 2242 | InstanceKlass* ik = m->method_holder(); | ||||
| 2243 | ClassLoaderData* cld = ik->class_loader_data(); | ||||
| 2244 | if (cld->jmethod_ids() == NULL__null) return false; | ||||
| 2245 | return (cld->jmethod_ids()->contains((Method**)mid)); | ||||
| 2246 | } | ||||
| 2247 | |||||
| 2248 | Method* Method::checked_resolve_jmethod_id(jmethodID mid) { | ||||
| 2249 | if (mid == NULL__null) return NULL__null; | ||||
| 2250 | Method* o = resolve_jmethod_id(mid); | ||||
| 2251 | if (o == NULL__null || o == JNIMethodBlock::_free_method) { | ||||
| 2252 | return NULL__null; | ||||
| 2253 | } | ||||
| 2254 | // Method should otherwise be valid. Assert for testing. | ||||
| 2255 | assert(is_valid_method(o), "should be valid jmethodid")do { if (!(is_valid_method(o))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2255, "assert(" "is_valid_method(o)" ") failed", "should be valid jmethodid" ); ::breakpoint(); } } while (0); | ||||
| 2256 | // If the method's class holder object is unreferenced, but not yet marked as | ||||
| 2257 | // unloaded, we need to return NULL here too because after a safepoint, its memory | ||||
| 2258 | // will be reclaimed. | ||||
| 2259 | return o->method_holder()->is_loader_alive() ? o : NULL__null; | ||||
| 2260 | }; | ||||
| 2261 | |||||
| 2262 | void Method::set_on_stack(const bool value) { | ||||
| 2263 | // Set both the method itself and its constant pool. The constant pool | ||||
| 2264 | // on stack means some method referring to it is also on the stack. | ||||
| 2265 | constants()->set_on_stack(value); | ||||
| 2266 | |||||
| 2267 | bool already_set = on_stack(); | ||||
| 2268 | _access_flags.set_on_stack(value); | ||||
| 2269 | if (value && !already_set) { | ||||
| 2270 | MetadataOnStackMark::record(this); | ||||
| 2271 | } | ||||
| 2272 | } | ||||
| 2273 | |||||
| 2274 | // Called when the class loader is unloaded to make all methods weak. | ||||
| 2275 | void Method::clear_jmethod_ids(ClassLoaderData* loader_data) { | ||||
| 2276 | loader_data->jmethod_ids()->clear_all_methods(); | ||||
| 2277 | } | ||||
| 2278 | |||||
| 2279 | bool Method::has_method_vptr(const void* ptr) { | ||||
| 2280 | Method m; | ||||
| 2281 | // This assumes that the vtbl pointer is the first word of a C++ object. | ||||
| 2282 | return dereference_vptr(&m) == dereference_vptr(ptr); | ||||
| 2283 | } | ||||
| 2284 | |||||
| 2285 | // Check that this pointer is valid by checking that the vtbl pointer matches | ||||
| 2286 | bool Method::is_valid_method(const Method* m) { | ||||
| 2287 | if (m
| ||||
| 2288 | return false; | ||||
| 2289 | } else if ((intptr_t(m) & (wordSize-1)) != 0) { | ||||
| 2290 | // Quick sanity check on pointer. | ||||
| 2291 | return false; | ||||
| 2292 | } else if (m->is_shared()) { | ||||
| 2293 | return CppVtables::is_valid_shared_method(m); | ||||
| 2294 | } else if (Metaspace::contains_non_shared(m)) { | ||||
| 2295 | return has_method_vptr((const void*)m); | ||||
| 2296 | } else { | ||||
| 2297 | return false; | ||||
| 2298 | } | ||||
| 2299 | } | ||||
| 2300 | |||||
| 2301 | #ifndef PRODUCT | ||||
| 2302 | void Method::print_jmethod_ids_count(const ClassLoaderData* loader_data, outputStream* out) { | ||||
| 2303 | out->print("%d", loader_data->jmethod_ids()->count_methods()); | ||||
| 2304 | } | ||||
| 2305 | #endif // PRODUCT | ||||
| 2306 | |||||
| 2307 | |||||
| 2308 | // Printing | ||||
| 2309 | |||||
| 2310 | #ifndef PRODUCT | ||||
| 2311 | |||||
| 2312 | void Method::print_on(outputStream* st) const { | ||||
| 2313 | ResourceMark rm; | ||||
| 2314 | assert(is_method(), "must be method")do { if (!(is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2314, "assert(" "is_method()" ") failed", "must be method") ; ::breakpoint(); } } while (0); | ||||
| 2315 | st->print_cr("%s", internal_name()); | ||||
| 2316 | st->print_cr(" - this oop: " INTPTR_FORMAT"0x%016" "l" "x", p2i(this)); | ||||
| 2317 | st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr(); | ||||
| 2318 | st->print (" - constants: " INTPTR_FORMAT"0x%016" "l" "x" " ", p2i(constants())); | ||||
| 2319 | constants()->print_value_on(st); st->cr(); | ||||
| 2320 | st->print (" - access: 0x%x ", access_flags().as_int()); access_flags().print_on(st); st->cr(); | ||||
| 2321 | st->print (" - name: "); name()->print_value_on(st); st->cr(); | ||||
| 2322 | st->print (" - signature: "); signature()->print_value_on(st); st->cr(); | ||||
| 2323 | st->print_cr(" - max stack: %d", max_stack()); | ||||
| 2324 | st->print_cr(" - max locals: %d", max_locals()); | ||||
| 2325 | st->print_cr(" - size of params: %d", size_of_parameters()); | ||||
| 2326 | st->print_cr(" - method size: %d", method_size()); | ||||
| 2327 | if (intrinsic_id() != vmIntrinsics::_none) | ||||
| 2328 | st->print_cr(" - intrinsic id: %d %s", vmIntrinsics::as_int(intrinsic_id()), vmIntrinsics::name_at(intrinsic_id())); | ||||
| 2329 | if (highest_comp_level() != CompLevel_none) | ||||
| 2330 | st->print_cr(" - highest level: %d", highest_comp_level()); | ||||
| 2331 | st->print_cr(" - vtable index: %d", _vtable_index); | ||||
| 2332 | st->print_cr(" - i2i entry: " INTPTR_FORMAT"0x%016" "l" "x", p2i(interpreter_entry())); | ||||
| 2333 | st->print( " - adapters: "); | ||||
| 2334 | AdapterHandlerEntry* a = ((Method*)this)->adapter(); | ||||
| 2335 | if (a == NULL__null) | ||||
| 2336 | st->print_cr(INTPTR_FORMAT"0x%016" "l" "x", p2i(a)); | ||||
| 2337 | else | ||||
| 2338 | a->print_adapter_on(st); | ||||
| 2339 | st->print_cr(" - compiled entry " INTPTR_FORMAT"0x%016" "l" "x", p2i(from_compiled_entry())); | ||||
| 2340 | st->print_cr(" - code size: %d", code_size()); | ||||
| 2341 | if (code_size() != 0) { | ||||
| 2342 | st->print_cr(" - code start: " INTPTR_FORMAT"0x%016" "l" "x", p2i(code_base())); | ||||
| 2343 | st->print_cr(" - code end (excl): " INTPTR_FORMAT"0x%016" "l" "x", p2i(code_base() + code_size())); | ||||
| 2344 | } | ||||
| 2345 | if (method_data() != NULL__null) { | ||||
| 2346 | st->print_cr(" - method data: " INTPTR_FORMAT"0x%016" "l" "x", p2i(method_data())); | ||||
| 2347 | } | ||||
| 2348 | st->print_cr(" - checked ex length: %d", checked_exceptions_length()); | ||||
| 2349 | if (checked_exceptions_length() > 0) { | ||||
| 2350 | CheckedExceptionElement* table = checked_exceptions_start(); | ||||
| 2351 | st->print_cr(" - checked ex start: " INTPTR_FORMAT"0x%016" "l" "x", p2i(table)); | ||||
| 2352 | if (Verbose) { | ||||
| 2353 | for (int i = 0; i < checked_exceptions_length(); i++) { | ||||
| 2354 | st->print_cr(" - throws %s", constants()->printable_name_at(table[i].class_cp_index)); | ||||
| 2355 | } | ||||
| 2356 | } | ||||
| 2357 | } | ||||
| 2358 | if (has_linenumber_table()) { | ||||
| 2359 | u_char* table = compressed_linenumber_table(); | ||||
| 2360 | st->print_cr(" - linenumber start: " INTPTR_FORMAT"0x%016" "l" "x", p2i(table)); | ||||
| 2361 | if (Verbose) { | ||||
| 2362 | CompressedLineNumberReadStream stream(table); | ||||
| 2363 | while (stream.read_pair()) { | ||||
| 2364 | st->print_cr(" - line %d: %d", stream.line(), stream.bci()); | ||||
| 2365 | } | ||||
| 2366 | } | ||||
| 2367 | } | ||||
| 2368 | st->print_cr(" - localvar length: %d", localvariable_table_length()); | ||||
| 2369 | if (localvariable_table_length() > 0) { | ||||
| 2370 | LocalVariableTableElement* table = localvariable_table_start(); | ||||
| 2371 | st->print_cr(" - localvar start: " INTPTR_FORMAT"0x%016" "l" "x", p2i(table)); | ||||
| 2372 | if (Verbose) { | ||||
| 2373 | for (int i = 0; i < localvariable_table_length(); i++) { | ||||
| 2374 | int bci = table[i].start_bci; | ||||
| 2375 | int len = table[i].length; | ||||
| 2376 | const char* name = constants()->printable_name_at(table[i].name_cp_index); | ||||
| 2377 | const char* desc = constants()->printable_name_at(table[i].descriptor_cp_index); | ||||
| 2378 | int slot = table[i].slot; | ||||
| 2379 | st->print_cr(" - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot); | ||||
| 2380 | } | ||||
| 2381 | } | ||||
| 2382 | } | ||||
| 2383 | if (code() != NULL__null) { | ||||
| 2384 | st->print (" - compiled code: "); | ||||
| 2385 | code()->print_value_on(st); | ||||
| 2386 | } | ||||
| 2387 | if (is_native()) { | ||||
| 2388 | st->print_cr(" - native function: " INTPTR_FORMAT"0x%016" "l" "x", p2i(native_function())); | ||||
| 2389 | st->print_cr(" - signature handler: " INTPTR_FORMAT"0x%016" "l" "x", p2i(signature_handler())); | ||||
| 2390 | } | ||||
| 2391 | } | ||||
| 2392 | |||||
| 2393 | void Method::print_linkage_flags(outputStream* st) { | ||||
| 2394 | access_flags().print_on(st); | ||||
| 2395 | if (is_default_method()) { | ||||
| 2396 | st->print("default "); | ||||
| 2397 | } | ||||
| 2398 | if (is_overpass()) { | ||||
| 2399 | st->print("overpass "); | ||||
| 2400 | } | ||||
| 2401 | } | ||||
| 2402 | #endif //PRODUCT | ||||
| 2403 | |||||
| 2404 | void Method::print_value_on(outputStream* st) const { | ||||
| 2405 | assert(is_method(), "must be method")do { if (!(is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2405, "assert(" "is_method()" ") failed", "must be method") ; ::breakpoint(); } } while (0); | ||||
| 2406 | st->print("%s", internal_name()); | ||||
| 2407 | print_address_on(st); | ||||
| 2408 | st->print(" "); | ||||
| 2409 | name()->print_value_on(st); | ||||
| 2410 | st->print(" "); | ||||
| 2411 | signature()->print_value_on(st); | ||||
| 2412 | st->print(" in "); | ||||
| 2413 | method_holder()->print_value_on(st); | ||||
| 2414 | if (WizardMode) st->print("#%d", _vtable_index); | ||||
| 2415 | if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals()); | ||||
| 2416 | if (WizardMode && code() != NULL__null) st->print(" ((nmethod*)%p)", code()); | ||||
| 2417 | } | ||||
| 2418 | |||||
| 2419 | // LogTouchedMethods and PrintTouchedMethods | ||||
| 2420 | |||||
| 2421 | // TouchedMethodRecord -- we can't use a HashtableEntry<Method*> because | ||||
| 2422 | // the Method may be garbage collected. Let's roll our own hash table. | ||||
| 2423 | class TouchedMethodRecord : CHeapObj<mtTracing> { | ||||
| 2424 | public: | ||||
| 2425 | // It's OK to store Symbols here because they will NOT be GC'ed if | ||||
| 2426 | // LogTouchedMethods is enabled. | ||||
| 2427 | TouchedMethodRecord* _next; | ||||
| 2428 | Symbol* _class_name; | ||||
| 2429 | Symbol* _method_name; | ||||
| 2430 | Symbol* _method_signature; | ||||
| 2431 | }; | ||||
| 2432 | |||||
| 2433 | static const int TOUCHED_METHOD_TABLE_SIZE = 20011; | ||||
| 2434 | static TouchedMethodRecord** _touched_method_table = NULL__null; | ||||
| 2435 | |||||
| 2436 | void Method::log_touched(Thread* current) { | ||||
| 2437 | |||||
| 2438 | const int table_size = TOUCHED_METHOD_TABLE_SIZE; | ||||
| 2439 | Symbol* my_class = klass_name(); | ||||
| 2440 | Symbol* my_name = name(); | ||||
| 2441 | Symbol* my_sig = signature(); | ||||
| 2442 | |||||
| 2443 | unsigned int hash = my_class->identity_hash() + | ||||
| 2444 | my_name->identity_hash() + | ||||
| 2445 | my_sig->identity_hash(); | ||||
| 2446 | juint index = juint(hash) % table_size; | ||||
| 2447 | |||||
| 2448 | MutexLocker ml(current, TouchedMethodLog_lock); | ||||
| 2449 | if (_touched_method_table == NULL__null) { | ||||
| 2450 | _touched_method_table = NEW_C_HEAP_ARRAY2(TouchedMethodRecord*, table_size,(TouchedMethodRecord**) (AllocateHeap((table_size) * sizeof(TouchedMethodRecord *), mtTracing, ((MemTracker::tracking_level() == NMT_detail) ? NativeCallStack(0) : NativeCallStack::empty_stack()))) | ||||
| 2451 | mtTracing, CURRENT_PC)(TouchedMethodRecord**) (AllocateHeap((table_size) * sizeof(TouchedMethodRecord *), mtTracing, ((MemTracker::tracking_level() == NMT_detail) ? NativeCallStack(0) : NativeCallStack::empty_stack()))); | ||||
| 2452 | memset(_touched_method_table, 0, sizeof(TouchedMethodRecord*)*table_size); | ||||
| 2453 | } | ||||
| 2454 | |||||
| 2455 | TouchedMethodRecord* ptr = _touched_method_table[index]; | ||||
| 2456 | while (ptr) { | ||||
| 2457 | if (ptr->_class_name == my_class && | ||||
| 2458 | ptr->_method_name == my_name && | ||||
| 2459 | ptr->_method_signature == my_sig) { | ||||
| 2460 | return; | ||||
| 2461 | } | ||||
| 2462 | if (ptr->_next == NULL__null) break; | ||||
| 2463 | ptr = ptr->_next; | ||||
| 2464 | } | ||||
| 2465 | TouchedMethodRecord* nptr = NEW_C_HEAP_OBJ(TouchedMethodRecord, mtTracing)(TouchedMethodRecord*) (AllocateHeap((1) * sizeof(TouchedMethodRecord ), mtTracing)); | ||||
| 2466 | my_class->increment_refcount(); | ||||
| 2467 | my_name->increment_refcount(); | ||||
| 2468 | my_sig->increment_refcount(); | ||||
| 2469 | nptr->_class_name = my_class; | ||||
| 2470 | nptr->_method_name = my_name; | ||||
| 2471 | nptr->_method_signature = my_sig; | ||||
| 2472 | nptr->_next = NULL__null; | ||||
| 2473 | |||||
| 2474 | if (ptr == NULL__null) { | ||||
| 2475 | // first | ||||
| 2476 | _touched_method_table[index] = nptr; | ||||
| 2477 | } else { | ||||
| 2478 | ptr->_next = nptr; | ||||
| 2479 | } | ||||
| 2480 | } | ||||
| 2481 | |||||
| 2482 | void Method::print_touched_methods(outputStream* out) { | ||||
| 2483 | MutexLocker ml(Thread::current()->is_VM_thread() ? NULL__null : TouchedMethodLog_lock); | ||||
| 2484 | out->print_cr("# Method::print_touched_methods version 1"); | ||||
| 2485 | if (_touched_method_table) { | ||||
| 2486 | for (int i = 0; i < TOUCHED_METHOD_TABLE_SIZE; i++) { | ||||
| 2487 | TouchedMethodRecord* ptr = _touched_method_table[i]; | ||||
| 2488 | while(ptr) { | ||||
| 2489 | ptr->_class_name->print_symbol_on(out); out->print("."); | ||||
| 2490 | ptr->_method_name->print_symbol_on(out); out->print(":"); | ||||
| 2491 | ptr->_method_signature->print_symbol_on(out); out->cr(); | ||||
| 2492 | ptr = ptr->_next; | ||||
| 2493 | } | ||||
| 2494 | } | ||||
| 2495 | } | ||||
| 2496 | } | ||||
| 2497 | |||||
| 2498 | // Verification | ||||
| 2499 | |||||
| 2500 | void Method::verify_on(outputStream* st) { | ||||
| 2501 | guarantee(is_method(), "object must be method")do { if (!(is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2501, "guarantee(" "is_method()" ") failed", "object must be method" ); ::breakpoint(); } } while (0); | ||||
| 2502 | guarantee(constants()->is_constantPool(), "should be constant pool")do { if (!(constants()->is_constantPool())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2502, "guarantee(" "constants()->is_constantPool()" ") failed" , "should be constant pool"); ::breakpoint(); } } while (0); | ||||
| 2503 | MethodData* md = method_data(); | ||||
| 2504 | guarantee(md == NULL ||do { if (!(md == __null || md->is_methodData())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2505, "guarantee(" "md == NULL || md->is_methodData()" ") failed" , "should be method data"); ::breakpoint(); } } while (0) | ||||
| 2505 | md->is_methodData(), "should be method data")do { if (!(md == __null || md->is_methodData())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/method.cpp" , 2505, "guarantee(" "md == NULL || md->is_methodData()" ") failed" , "should be method data"); ::breakpoint(); } } while (0); | ||||
| 2506 | } |
| 1 | /* | |||
| 2 | * Copyright (c) 1997, 2021, 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 | #ifndef SHARE_UTILITIES_GLOBALDEFINITIONS_HPP | |||
| 26 | #define SHARE_UTILITIES_GLOBALDEFINITIONS_HPP | |||
| 27 | ||||
| 28 | #include "utilities/compilerWarnings.hpp" | |||
| 29 | #include "utilities/debug.hpp" | |||
| 30 | #include "utilities/macros.hpp" | |||
| 31 | ||||
| 32 | // Get constants like JVM_T_CHAR and JVM_SIGNATURE_INT, before pulling in <jvm.h>. | |||
| 33 | #include "classfile_constants.h" | |||
| 34 | ||||
| 35 | #include COMPILER_HEADER(utilities/globalDefinitions)"utilities/globalDefinitions_gcc.hpp" | |||
| 36 | ||||
| 37 | #include <cstddef> | |||
| 38 | ||||
| 39 | class oopDesc; | |||
| 40 | ||||
| 41 | // Defaults for macros that might be defined per compiler. | |||
| 42 | #ifndef NOINLINE__attribute__ ((noinline)) | |||
| 43 | #define NOINLINE__attribute__ ((noinline)) | |||
| 44 | #endif | |||
| 45 | #ifndef ALWAYSINLINEinline __attribute__ ((always_inline)) | |||
| 46 | #define ALWAYSINLINEinline __attribute__ ((always_inline)) inline | |||
| 47 | #endif | |||
| 48 | ||||
| 49 | #ifndef ATTRIBUTE_ALIGNED | |||
| 50 | #define ATTRIBUTE_ALIGNED(x)__attribute__((aligned(x))) | |||
| 51 | #endif | |||
| 52 | ||||
| 53 | #ifndef ATTRIBUTE_FLATTEN__attribute__ ((flatten)) | |||
| 54 | #define ATTRIBUTE_FLATTEN__attribute__ ((flatten)) | |||
| 55 | #endif | |||
| 56 | ||||
| 57 | // These are #defines to selectively turn on/off the Print(Opto)Assembly | |||
| 58 | // capabilities. Choices should be led by a tradeoff between | |||
| 59 | // code size and improved supportability. | |||
| 60 | // if PRINT_ASSEMBLY then PRINT_ABSTRACT_ASSEMBLY must be true as well | |||
| 61 | // to have a fallback in case hsdis is not available. | |||
| 62 | #if defined(PRODUCT) | |||
| 63 | #define SUPPORT_ABSTRACT_ASSEMBLY | |||
| 64 | #define SUPPORT_ASSEMBLY | |||
| 65 | #undef SUPPORT_OPTO_ASSEMBLY // Can't activate. In PRODUCT, many dump methods are missing. | |||
| 66 | #undef SUPPORT_DATA_STRUCTS // Of limited use. In PRODUCT, many print methods are empty. | |||
| 67 | #else | |||
| 68 | #define SUPPORT_ABSTRACT_ASSEMBLY | |||
| 69 | #define SUPPORT_ASSEMBLY | |||
| 70 | #define SUPPORT_OPTO_ASSEMBLY | |||
| 71 | #define SUPPORT_DATA_STRUCTS | |||
| 72 | #endif | |||
| 73 | #if defined(SUPPORT_ASSEMBLY) && !defined(SUPPORT_ABSTRACT_ASSEMBLY) | |||
| 74 | #define SUPPORT_ABSTRACT_ASSEMBLY | |||
| 75 | #endif | |||
| 76 | ||||
| 77 | // This file holds all globally used constants & types, class (forward) | |||
| 78 | // declarations and a few frequently used utility functions. | |||
| 79 | ||||
| 80 | // Declare the named class to be noncopyable. This macro must be followed by | |||
| 81 | // a semi-colon. The macro provides deleted declarations for the class's copy | |||
| 82 | // constructor and assignment operator. Because these operations are deleted, | |||
| 83 | // they cannot be defined and potential callers will fail to compile. | |||
| 84 | #define NONCOPYABLE(C)C(C const&) = delete; C& operator=(C const&) = delete C(C const&) = delete; C& operator=(C const&) = delete /* next token must be ; */ | |||
| 85 | ||||
| 86 | ||||
| 87 | //---------------------------------------------------------------------------------------------------- | |||
| 88 | // Printf-style formatters for fixed- and variable-width types as pointers and | |||
| 89 | // integers. These are derived from the definitions in inttypes.h. If the platform | |||
| 90 | // doesn't provide appropriate definitions, they should be provided in | |||
| 91 | // the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp) | |||
| 92 | ||||
| 93 | #define BOOL_TO_STR(_b_)((_b_) ? "true" : "false") ((_b_) ? "true" : "false") | |||
| 94 | ||||
| 95 | // Format 32-bit quantities. | |||
| 96 | #define INT32_FORMAT"%" "d" "%" PRId32"d" | |||
| 97 | #define UINT32_FORMAT"%" "u" "%" PRIu32"u" | |||
| 98 | #define INT32_FORMAT_W(width)"%" "width" "d" "%" #width PRId32"d" | |||
| 99 | #define UINT32_FORMAT_W(width)"%" "width" "u" "%" #width PRIu32"u" | |||
| 100 | ||||
| 101 | #define PTR32_FORMAT"0x%08" "x" "0x%08" PRIx32"x" | |||
| 102 | #define PTR32_FORMAT_W(width)"0x%" "width" "x" "0x%" #width PRIx32"x" | |||
| 103 | ||||
| 104 | // Format 64-bit quantities. | |||
| 105 | #define INT64_FORMAT"%" "l" "d" "%" PRId64"l" "d" | |||
| 106 | #define UINT64_FORMAT"%" "l" "u" "%" PRIu64"l" "u" | |||
| 107 | #define UINT64_FORMAT_X"%" "l" "x" "%" PRIx64"l" "x" | |||
| 108 | #define INT64_FORMAT_W(width)"%" "width" "l" "d" "%" #width PRId64"l" "d" | |||
| 109 | #define UINT64_FORMAT_W(width)"%" "width" "l" "u" "%" #width PRIu64"l" "u" | |||
| 110 | #define UINT64_FORMAT_X_W(width)"%" "width" "l" "x" "%" #width PRIx64"l" "x" | |||
| 111 | ||||
| 112 | #define PTR64_FORMAT"0x%016" "l" "x" "0x%016" PRIx64"l" "x" | |||
| 113 | ||||
| 114 | // Format jlong, if necessary | |||
| 115 | #ifndef JLONG_FORMAT"%" "l" "d" | |||
| 116 | #define JLONG_FORMAT"%" "l" "d" INT64_FORMAT"%" "l" "d" | |||
| 117 | #endif | |||
| 118 | #ifndef JLONG_FORMAT_W | |||
| 119 | #define JLONG_FORMAT_W(width)"%" "width" "l" "d" INT64_FORMAT_W(width)"%" "width" "l" "d" | |||
| 120 | #endif | |||
| 121 | #ifndef JULONG_FORMAT"%" "l" "u" | |||
| 122 | #define JULONG_FORMAT"%" "l" "u" UINT64_FORMAT"%" "l" "u" | |||
| 123 | #endif | |||
| 124 | #ifndef JULONG_FORMAT_X"%" "l" "x" | |||
| 125 | #define JULONG_FORMAT_X"%" "l" "x" UINT64_FORMAT_X"%" "l" "x" | |||
| 126 | #endif | |||
| 127 | ||||
| 128 | // Format pointers which change size between 32- and 64-bit. | |||
| 129 | #ifdef _LP641 | |||
| 130 | #define INTPTR_FORMAT"0x%016" "l" "x" "0x%016" PRIxPTR"l" "x" | |||
| 131 | #define PTR_FORMAT"0x%016" "l" "x" "0x%016" PRIxPTR"l" "x" | |||
| 132 | #else // !_LP64 | |||
| 133 | #define INTPTR_FORMAT"0x%016" "l" "x" "0x%08" PRIxPTR"l" "x" | |||
| 134 | #define PTR_FORMAT"0x%016" "l" "x" "0x%08" PRIxPTR"l" "x" | |||
| 135 | #endif // _LP64 | |||
| 136 | ||||
| 137 | // Format pointers without leading zeros | |||
| 138 | #define INTPTRNZ_FORMAT"0x%" "l" "x" "0x%" PRIxPTR"l" "x" | |||
| 139 | ||||
| 140 | #define INTPTR_FORMAT_W(width)"%" "width" "l" "x" "%" #width PRIxPTR"l" "x" | |||
| 141 | ||||
| 142 | #define SSIZE_FORMAT"%" "l" "d" "%" PRIdPTR"l" "d" | |||
| 143 | #define SIZE_FORMAT"%" "l" "u" "%" PRIuPTR"l" "u" | |||
| 144 | #define SIZE_FORMAT_HEX"0x%" "l" "x" "0x%" PRIxPTR"l" "x" | |||
| 145 | #define SSIZE_FORMAT_W(width)"%" "width" "l" "d" "%" #width PRIdPTR"l" "d" | |||
| 146 | #define SIZE_FORMAT_W(width)"%" "width" "l" "u" "%" #width PRIuPTR"l" "u" | |||
| 147 | #define SIZE_FORMAT_HEX_W(width)"0x%" "width" "l" "x" "0x%" #width PRIxPTR"l" "x" | |||
| 148 | ||||
| 149 | #define INTX_FORMAT"%" "l" "d" "%" PRIdPTR"l" "d" | |||
| 150 | #define UINTX_FORMAT"%" "l" "u" "%" PRIuPTR"l" "u" | |||
| 151 | #define INTX_FORMAT_W(width)"%" "width" "l" "d" "%" #width PRIdPTR"l" "d" | |||
| 152 | #define UINTX_FORMAT_W(width)"%" "width" "l" "u" "%" #width PRIuPTR"l" "u" | |||
| 153 | ||||
| 154 | // Convert pointer to intptr_t, for use in printing pointers. | |||
| 155 | inline intptr_t p2i(const volatile void* p) { | |||
| 156 | return (intptr_t) p; | |||
| 157 | } | |||
| 158 | ||||
| 159 | //---------------------------------------------------------------------------------------------------- | |||
| 160 | // Constants | |||
| 161 | ||||
| 162 | const int LogBytesPerShort = 1; | |||
| 163 | const int LogBytesPerInt = 2; | |||
| 164 | #ifdef _LP641 | |||
| 165 | const int LogBytesPerWord = 3; | |||
| 166 | #else | |||
| 167 | const int LogBytesPerWord = 2; | |||
| 168 | #endif | |||
| 169 | const int LogBytesPerLong = 3; | |||
| 170 | ||||
| 171 | const int BytesPerShort = 1 << LogBytesPerShort; | |||
| 172 | const int BytesPerInt = 1 << LogBytesPerInt; | |||
| 173 | const int BytesPerWord = 1 << LogBytesPerWord; | |||
| 174 | const int BytesPerLong = 1 << LogBytesPerLong; | |||
| 175 | ||||
| 176 | const int LogBitsPerByte = 3; | |||
| 177 | const int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort; | |||
| 178 | const int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt; | |||
| 179 | const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord; | |||
| 180 | const int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong; | |||
| 181 | ||||
| 182 | const int BitsPerByte = 1 << LogBitsPerByte; | |||
| 183 | const int BitsPerShort = 1 << LogBitsPerShort; | |||
| 184 | const int BitsPerInt = 1 << LogBitsPerInt; | |||
| 185 | const int BitsPerWord = 1 << LogBitsPerWord; | |||
| 186 | const int BitsPerLong = 1 << LogBitsPerLong; | |||
| 187 | ||||
| 188 | const int WordAlignmentMask = (1 << LogBytesPerWord) - 1; | |||
| 189 | const int LongAlignmentMask = (1 << LogBytesPerLong) - 1; | |||
| 190 | ||||
| 191 | const int WordsPerLong = 2; // Number of stack entries for longs | |||
| 192 | ||||
| 193 | const int oopSize = sizeof(char*); // Full-width oop | |||
| 194 | extern int heapOopSize; // Oop within a java object | |||
| 195 | const int wordSize = sizeof(char*); | |||
| 196 | const int longSize = sizeof(jlong); | |||
| 197 | const int jintSize = sizeof(jint); | |||
| 198 | const int size_tSize = sizeof(size_t); | |||
| 199 | ||||
| 200 | const int BytesPerOop = BytesPerWord; // Full-width oop | |||
| 201 | ||||
| 202 | extern int LogBytesPerHeapOop; // Oop within a java object | |||
| 203 | extern int LogBitsPerHeapOop; | |||
| 204 | extern int BytesPerHeapOop; | |||
| 205 | extern int BitsPerHeapOop; | |||
| 206 | ||||
| 207 | const int BitsPerJavaInteger = 32; | |||
| 208 | const int BitsPerJavaLong = 64; | |||
| 209 | const int BitsPerSize_t = size_tSize * BitsPerByte; | |||
| 210 | ||||
| 211 | // Size of a char[] needed to represent a jint as a string in decimal. | |||
| 212 | const int jintAsStringSize = 12; | |||
| 213 | ||||
| 214 | // An opaque type, so that HeapWord* can be a generic pointer into the heap. | |||
| 215 | // We require that object sizes be measured in units of heap words (e.g. | |||
| 216 | // pointer-sized values), so that given HeapWord* hw, | |||
| 217 | // hw += oop(hw)->foo(); | |||
| 218 | // works, where foo is a method (like size or scavenge) that returns the | |||
| 219 | // object size. | |||
| 220 | class HeapWordImpl; // Opaque, never defined. | |||
| 221 | typedef HeapWordImpl* HeapWord; | |||
| 222 | ||||
| 223 | // Analogous opaque struct for metadata allocated from metaspaces. | |||
| 224 | class MetaWordImpl; // Opaque, never defined. | |||
| 225 | typedef MetaWordImpl* MetaWord; | |||
| 226 | ||||
| 227 | // HeapWordSize must be 2^LogHeapWordSize. | |||
| 228 | const int HeapWordSize = sizeof(HeapWord); | |||
| 229 | #ifdef _LP641 | |||
| 230 | const int LogHeapWordSize = 3; | |||
| 231 | #else | |||
| 232 | const int LogHeapWordSize = 2; | |||
| 233 | #endif | |||
| 234 | const int HeapWordsPerLong = BytesPerLong / HeapWordSize; | |||
| 235 | const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize; | |||
| 236 | ||||
| 237 | // The minimum number of native machine words necessary to contain "byte_size" | |||
| 238 | // bytes. | |||
| 239 | inline size_t heap_word_size(size_t byte_size) { | |||
| 240 | return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize; | |||
| 241 | } | |||
| 242 | ||||
| 243 | inline jfloat jfloat_cast(jint x); | |||
| 244 | inline jdouble jdouble_cast(jlong x); | |||
| 245 | ||||
| 246 | //------------------------------------------- | |||
| 247 | // Constant for jlong (standardized by C++11) | |||
| 248 | ||||
| 249 | // Build a 64bit integer constant | |||
| 250 | #define CONST64(x)(xLL) (x ## LL) | |||
| 251 | #define UCONST64(x)(xULL) (x ## ULL) | |||
| 252 | ||||
| 253 | const jlong min_jlong = CONST64(0x8000000000000000)(0x8000000000000000LL); | |||
| 254 | const jlong max_jlong = CONST64(0x7fffffffffffffff)(0x7fffffffffffffffLL); | |||
| 255 | ||||
| 256 | //------------------------------------------- | |||
| 257 | // Constant for jdouble | |||
| 258 | const jlong min_jlongDouble = CONST64(0x0000000000000001)(0x0000000000000001LL); | |||
| 259 | const jdouble min_jdouble = jdouble_cast(min_jlongDouble); | |||
| 260 | const jlong max_jlongDouble = CONST64(0x7fefffffffffffff)(0x7fefffffffffffffLL); | |||
| 261 | const jdouble max_jdouble = jdouble_cast(max_jlongDouble); | |||
| 262 | ||||
| 263 | const size_t K = 1024; | |||
| 264 | const size_t M = K*K; | |||
| 265 | const size_t G = M*K; | |||
| 266 | const size_t HWperKB = K / sizeof(HeapWord); | |||
| 267 | ||||
| 268 | // Constants for converting from a base unit to milli-base units. For | |||
| 269 | // example from seconds to milliseconds and microseconds | |||
| 270 | ||||
| 271 | const int MILLIUNITS = 1000; // milli units per base unit | |||
| 272 | const int MICROUNITS = 1000000; // micro units per base unit | |||
| 273 | const int NANOUNITS = 1000000000; // nano units per base unit | |||
| 274 | const int NANOUNITS_PER_MILLIUNIT = NANOUNITS / MILLIUNITS; | |||
| 275 | ||||
| 276 | const jlong NANOSECS_PER_SEC = CONST64(1000000000)(1000000000LL); | |||
| 277 | const jint NANOSECS_PER_MILLISEC = 1000000; | |||
| 278 | ||||
| 279 | ||||
| 280 | // Unit conversion functions | |||
| 281 | // The caller is responsible for considering overlow. | |||
| 282 | ||||
| 283 | inline int64_t nanos_to_millis(int64_t nanos) { | |||
| 284 | return nanos / NANOUNITS_PER_MILLIUNIT; | |||
| 285 | } | |||
| 286 | inline int64_t millis_to_nanos(int64_t millis) { | |||
| 287 | return millis * NANOUNITS_PER_MILLIUNIT; | |||
| 288 | } | |||
| 289 | ||||
| 290 | // Proper units routines try to maintain at least three significant digits. | |||
| 291 | // In worst case, it would print five significant digits with lower prefix. | |||
| 292 | // G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow, | |||
| 293 | // and therefore we need to be careful. | |||
| 294 | ||||
| 295 | inline const char* proper_unit_for_byte_size(size_t s) { | |||
| 296 | #ifdef _LP641 | |||
| 297 | if (s >= 100*G) { | |||
| 298 | return "G"; | |||
| 299 | } | |||
| 300 | #endif | |||
| 301 | if (s >= 100*M) { | |||
| 302 | return "M"; | |||
| 303 | } else if (s >= 100*K) { | |||
| 304 | return "K"; | |||
| 305 | } else { | |||
| 306 | return "B"; | |||
| 307 | } | |||
| 308 | } | |||
| 309 | ||||
| 310 | template <class T> | |||
| 311 | inline T byte_size_in_proper_unit(T s) { | |||
| 312 | #ifdef _LP641 | |||
| 313 | if (s >= 100*G) { | |||
| 314 | return (T)(s/G); | |||
| 315 | } | |||
| 316 | #endif | |||
| 317 | if (s >= 100*M) { | |||
| 318 | return (T)(s/M); | |||
| 319 | } else if (s >= 100*K) { | |||
| 320 | return (T)(s/K); | |||
| 321 | } else { | |||
| 322 | return s; | |||
| 323 | } | |||
| 324 | } | |||
| 325 | ||||
| 326 | inline const char* exact_unit_for_byte_size(size_t s) { | |||
| 327 | #ifdef _LP641 | |||
| 328 | if (s >= G && (s % G) == 0) { | |||
| 329 | return "G"; | |||
| 330 | } | |||
| 331 | #endif | |||
| 332 | if (s >= M && (s % M) == 0) { | |||
| 333 | return "M"; | |||
| 334 | } | |||
| 335 | if (s >= K && (s % K) == 0) { | |||
| 336 | return "K"; | |||
| 337 | } | |||
| 338 | return "B"; | |||
| 339 | } | |||
| 340 | ||||
| 341 | inline size_t byte_size_in_exact_unit(size_t s) { | |||
| 342 | #ifdef _LP641 | |||
| 343 | if (s >= G && (s % G) == 0) { | |||
| 344 | return s / G; | |||
| 345 | } | |||
| 346 | #endif | |||
| 347 | if (s >= M && (s % M) == 0) { | |||
| 348 | return s / M; | |||
| 349 | } | |||
| 350 | if (s >= K && (s % K) == 0) { | |||
| 351 | return s / K; | |||
| 352 | } | |||
| 353 | return s; | |||
| 354 | } | |||
| 355 | ||||
| 356 | // Memory size transition formatting. | |||
| 357 | ||||
| 358 | #define HEAP_CHANGE_FORMAT"%s: " "%" "l" "u" "K(" "%" "l" "u" "K)->" "%" "l" "u" "K(" "%" "l" "u" "K)" "%s: " SIZE_FORMAT"%" "l" "u" "K(" SIZE_FORMAT"%" "l" "u" "K)->" SIZE_FORMAT"%" "l" "u" "K(" SIZE_FORMAT"%" "l" "u" "K)" | |||
| 359 | ||||
| 360 | #define HEAP_CHANGE_FORMAT_ARGS(_name_, _prev_used_, _prev_capacity_, _used_, _capacity_)(_name_), (_prev_used_) / K, (_prev_capacity_) / K, (_used_) / K, (_capacity_) / K \ | |||
| 361 | (_name_), (_prev_used_) / K, (_prev_capacity_) / K, (_used_) / K, (_capacity_) / K | |||
| 362 | ||||
| 363 | //---------------------------------------------------------------------------------------------------- | |||
| 364 | // VM type definitions | |||
| 365 | ||||
| 366 | // intx and uintx are the 'extended' int and 'extended' unsigned int types; | |||
| 367 | // they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform. | |||
| 368 | ||||
| 369 | typedef intptr_t intx; | |||
| 370 | typedef uintptr_t uintx; | |||
| 371 | ||||
| 372 | const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1); | |||
| 373 | const intx max_intx = (uintx)min_intx - 1; | |||
| 374 | const uintx max_uintx = (uintx)-1; | |||
| 375 | ||||
| 376 | // Table of values: | |||
| 377 | // sizeof intx 4 8 | |||
| 378 | // min_intx 0x80000000 0x8000000000000000 | |||
| 379 | // max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF | |||
| 380 | // max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF | |||
| 381 | ||||
| 382 | typedef unsigned int uint; NEEDS_CLEANUP | |||
| 383 | ||||
| 384 | ||||
| 385 | //---------------------------------------------------------------------------------------------------- | |||
| 386 | // Java type definitions | |||
| 387 | ||||
| 388 | // All kinds of 'plain' byte addresses | |||
| 389 | typedef signed char s_char; | |||
| 390 | typedef unsigned char u_char; | |||
| 391 | typedef u_char* address; | |||
| 392 | typedef uintptr_t address_word; // unsigned integer which will hold a pointer | |||
| 393 | // except for some implementations of a C++ | |||
| 394 | // linkage pointer to function. Should never | |||
| 395 | // need one of those to be placed in this | |||
| 396 | // type anyway. | |||
| 397 | ||||
| 398 | // Utility functions to "portably" (?) bit twiddle pointers | |||
| 399 | // Where portable means keep ANSI C++ compilers quiet | |||
| 400 | ||||
| 401 | inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); } | |||
| 402 | inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); } | |||
| 403 | ||||
| 404 | // Utility functions to "portably" make cast to/from function pointers. | |||
| 405 | ||||
| 406 | inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; } | |||
| 407 | inline address_word castable_address(address x) { return address_word(x) ; } | |||
| 408 | inline address_word castable_address(void* x) { return address_word(x) ; } | |||
| 409 | ||||
| 410 | // Pointer subtraction. | |||
| 411 | // The idea here is to avoid ptrdiff_t, which is signed and so doesn't have | |||
| 412 | // the range we might need to find differences from one end of the heap | |||
| 413 | // to the other. | |||
| 414 | // A typical use might be: | |||
| 415 | // if (pointer_delta(end(), top()) >= size) { | |||
| 416 | // // enough room for an object of size | |||
| 417 | // ... | |||
| 418 | // and then additions like | |||
| 419 | // ... top() + size ... | |||
| 420 | // are safe because we know that top() is at least size below end(). | |||
| 421 | inline size_t pointer_delta(const volatile void* left, | |||
| 422 | const volatile void* right, | |||
| 423 | size_t element_size) { | |||
| 424 | assert(left >= right, "avoid underflow - left: " PTR_FORMAT " right: " PTR_FORMAT, p2i(left), p2i(right))do { if (!(left >= right)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 424, "assert(" "left >= right" ") failed", "avoid underflow - left: " "0x%016" "l" "x" " right: " "0x%016" "l" "x", p2i(left), p2i (right)); ::breakpoint(); } } while (0); | |||
| 425 | return (((uintptr_t) left) - ((uintptr_t) right)) / element_size; | |||
| 426 | } | |||
| 427 | ||||
| 428 | // A version specialized for HeapWord*'s. | |||
| 429 | inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) { | |||
| 430 | return pointer_delta(left, right, sizeof(HeapWord)); | |||
| 431 | } | |||
| 432 | // A version specialized for MetaWord*'s. | |||
| 433 | inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) { | |||
| 434 | return pointer_delta(left, right, sizeof(MetaWord)); | |||
| 435 | } | |||
| 436 | ||||
| 437 | // | |||
| 438 | // ANSI C++ does not allow casting from one pointer type to a function pointer | |||
| 439 | // directly without at best a warning. This macro accomplishes it silently | |||
| 440 | // In every case that is present at this point the value be cast is a pointer | |||
| 441 | // to a C linkage function. In some case the type used for the cast reflects | |||
| 442 | // that linkage and a picky compiler would not complain. In other cases because | |||
| 443 | // there is no convenient place to place a typedef with extern C linkage (i.e | |||
| 444 | // a platform dependent header file) it doesn't. At this point no compiler seems | |||
| 445 | // picky enough to catch these instances (which are few). It is possible that | |||
| 446 | // using templates could fix these for all cases. This use of templates is likely | |||
| 447 | // so far from the middle of the road that it is likely to be problematic in | |||
| 448 | // many C++ compilers. | |||
| 449 | // | |||
| 450 | #define CAST_TO_FN_PTR(func_type, value)(reinterpret_cast<func_type>(value)) (reinterpret_cast<func_type>(value)) | |||
| 451 | #define CAST_FROM_FN_PTR(new_type, func_ptr)((new_type)((address_word)(func_ptr))) ((new_type)((address_word)(func_ptr))) | |||
| 452 | ||||
| 453 | // In many places we've added C-style casts to silence compiler | |||
| 454 | // warnings, for example when truncating a size_t to an int when we | |||
| 455 | // know the size_t is a small struct. Such casts are risky because | |||
| 456 | // they effectively disable useful compiler warnings. We can make our | |||
| 457 | // lives safer with this function, which ensures that any cast is | |||
| 458 | // reversible without loss of information. It doesn't check | |||
| 459 | // everything: it isn't intended to make sure that pointer types are | |||
| 460 | // compatible, for example. | |||
| 461 | template <typename T2, typename T1> | |||
| 462 | T2 checked_cast(T1 thing) { | |||
| 463 | T2 result = static_cast<T2>(thing); | |||
| 464 | assert(static_cast<T1>(result) == thing, "must be")do { if (!(static_cast<T1>(result) == thing)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 464, "assert(" "static_cast<T1>(result) == thing" ") failed" , "must be"); ::breakpoint(); } } while (0); | |||
| 465 | return result; | |||
| 466 | } | |||
| 467 | ||||
| 468 | // Need the correct linkage to call qsort without warnings | |||
| 469 | extern "C" { | |||
| 470 | typedef int (*_sort_Fn)(const void *, const void *); | |||
| 471 | } | |||
| 472 | ||||
| 473 | // Unsigned byte types for os and stream.hpp | |||
| 474 | ||||
| 475 | // Unsigned one, two, four and eigth byte quantities used for describing | |||
| 476 | // the .class file format. See JVM book chapter 4. | |||
| 477 | ||||
| 478 | typedef jubyte u1; | |||
| 479 | typedef jushort u2; | |||
| 480 | typedef juint u4; | |||
| 481 | typedef julong u8; | |||
| 482 | ||||
| 483 | const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte | |||
| 484 | const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort | |||
| 485 | const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint | |||
| 486 | const julong max_julong = (julong)-1; // 0xFF....FF largest julong | |||
| 487 | ||||
| 488 | typedef jbyte s1; | |||
| 489 | typedef jshort s2; | |||
| 490 | typedef jint s4; | |||
| 491 | typedef jlong s8; | |||
| 492 | ||||
| 493 | const jbyte min_jbyte = -(1 << 7); // smallest jbyte | |||
| 494 | const jbyte max_jbyte = (1 << 7) - 1; // largest jbyte | |||
| 495 | const jshort min_jshort = -(1 << 15); // smallest jshort | |||
| 496 | const jshort max_jshort = (1 << 15) - 1; // largest jshort | |||
| 497 | ||||
| 498 | const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint | |||
| 499 | const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint | |||
| 500 | ||||
| 501 | const jint min_jintFloat = (jint)(0x00000001); | |||
| 502 | const jfloat min_jfloat = jfloat_cast(min_jintFloat); | |||
| 503 | const jint max_jintFloat = (jint)(0x7f7fffff); | |||
| 504 | const jfloat max_jfloat = jfloat_cast(max_jintFloat); | |||
| 505 | ||||
| 506 | //---------------------------------------------------------------------------------------------------- | |||
| 507 | // JVM spec restrictions | |||
| 508 | ||||
| 509 | const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134) | |||
| 510 | ||||
| 511 | //---------------------------------------------------------------------------------------------------- | |||
| 512 | // old CDS options | |||
| 513 | extern bool DumpSharedSpaces; | |||
| 514 | extern bool DynamicDumpSharedSpaces; | |||
| 515 | extern bool RequireSharedSpaces; | |||
| 516 | extern "C" { | |||
| 517 | // Make sure UseSharedSpaces is accessible to the serviceability agent. | |||
| 518 | extern JNIEXPORT__attribute__((visibility("default"))) jboolean UseSharedSpaces; | |||
| 519 | } | |||
| 520 | ||||
| 521 | //---------------------------------------------------------------------------------------------------- | |||
| 522 | // Object alignment, in units of HeapWords. | |||
| 523 | // | |||
| 524 | // Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and | |||
| 525 | // reference fields can be naturally aligned. | |||
| 526 | ||||
| 527 | extern int MinObjAlignment; | |||
| 528 | extern int MinObjAlignmentInBytes; | |||
| 529 | extern int MinObjAlignmentInBytesMask; | |||
| 530 | ||||
| 531 | extern int LogMinObjAlignment; | |||
| 532 | extern int LogMinObjAlignmentInBytes; | |||
| 533 | ||||
| 534 | const int LogKlassAlignmentInBytes = 3; | |||
| 535 | const int LogKlassAlignment = LogKlassAlignmentInBytes - LogHeapWordSize; | |||
| 536 | const int KlassAlignmentInBytes = 1 << LogKlassAlignmentInBytes; | |||
| 537 | const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize; | |||
| 538 | ||||
| 539 | // Maximal size of heap where unscaled compression can be used. Also upper bound | |||
| 540 | // for heap placement: 4GB. | |||
| 541 | const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1); | |||
| 542 | // Maximal size of heap where compressed oops can be used. Also upper bound for heap | |||
| 543 | // placement for zero based compression algorithm: UnscaledOopHeapMax << LogMinObjAlignmentInBytes. | |||
| 544 | extern uint64_t OopEncodingHeapMax; | |||
| 545 | ||||
| 546 | // Maximal size of compressed class space. Above this limit compression is not possible. | |||
| 547 | // Also upper bound for placement of zero based class space. (Class space is further limited | |||
| 548 | // to be < 3G, see arguments.cpp.) | |||
| 549 | const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes; | |||
| 550 | ||||
| 551 | // Machine dependent stuff | |||
| 552 | ||||
| 553 | // The maximum size of the code cache. Can be overridden by targets. | |||
| 554 | #define CODE_CACHE_SIZE_LIMIT(2*G) (2*G) | |||
| 555 | // Allow targets to reduce the default size of the code cache. | |||
| 556 | #define CODE_CACHE_DEFAULT_LIMIT(2*G) CODE_CACHE_SIZE_LIMIT(2*G) | |||
| 557 | ||||
| 558 | #include CPU_HEADER(globalDefinitions)"globalDefinitions_x86.hpp" | |||
| 559 | ||||
| 560 | // To assure the IRIW property on processors that are not multiple copy | |||
| 561 | // atomic, sync instructions must be issued between volatile reads to | |||
| 562 | // assure their ordering, instead of after volatile stores. | |||
| 563 | // (See "A Tutorial Introduction to the ARM and POWER Relaxed Memory Models" | |||
| 564 | // by Luc Maranget, Susmit Sarkar and Peter Sewell, INRIA/Cambridge) | |||
| 565 | #ifdef CPU_MULTI_COPY_ATOMIC | |||
| 566 | // Not needed. | |||
| 567 | const bool support_IRIW_for_not_multiple_copy_atomic_cpu = false; | |||
| 568 | #else | |||
| 569 | // From all non-multi-copy-atomic architectures, only PPC64 supports IRIW at the moment. | |||
| 570 | // Final decision is subject to JEP 188: Java Memory Model Update. | |||
| 571 | const bool support_IRIW_for_not_multiple_copy_atomic_cpu = PPC64_ONLY(true) NOT_PPC64(false)false; | |||
| 572 | #endif | |||
| 573 | ||||
| 574 | // The expected size in bytes of a cache line, used to pad data structures. | |||
| 575 | #ifndef DEFAULT_CACHE_LINE_SIZE128 | |||
| 576 | #define DEFAULT_CACHE_LINE_SIZE128 64 | |||
| 577 | #endif | |||
| 578 | ||||
| 579 | ||||
| 580 | //---------------------------------------------------------------------------------------------------- | |||
| 581 | // Utility macros for compilers | |||
| 582 | // used to silence compiler warnings | |||
| 583 | ||||
| 584 | #define Unused_Variable(var)var var | |||
| 585 | ||||
| 586 | ||||
| 587 | //---------------------------------------------------------------------------------------------------- | |||
| 588 | // Miscellaneous | |||
| 589 | ||||
| 590 | // 6302670 Eliminate Hotspot __fabsf dependency | |||
| 591 | // All fabs() callers should call this function instead, which will implicitly | |||
| 592 | // convert the operand to double, avoiding a dependency on __fabsf which | |||
| 593 | // doesn't exist in early versions of Solaris 8. | |||
| 594 | inline double fabsd(double value) { | |||
| 595 | return fabs(value); | |||
| 596 | } | |||
| 597 | ||||
| 598 | // Returns numerator/denominator as percentage value from 0 to 100. If denominator | |||
| 599 | // is zero, return 0.0. | |||
| 600 | template<typename T> | |||
| 601 | inline double percent_of(T numerator, T denominator) { | |||
| 602 | return denominator != 0 ? (double)numerator / denominator * 100.0 : 0.0; | |||
| 603 | } | |||
| 604 | ||||
| 605 | //---------------------------------------------------------------------------------------------------- | |||
| 606 | // Special casts | |||
| 607 | // Cast floats into same-size integers and vice-versa w/o changing bit-pattern | |||
| 608 | typedef union { | |||
| 609 | jfloat f; | |||
| 610 | jint i; | |||
| 611 | } FloatIntConv; | |||
| 612 | ||||
| 613 | typedef union { | |||
| 614 | jdouble d; | |||
| 615 | jlong l; | |||
| 616 | julong ul; | |||
| 617 | } DoubleLongConv; | |||
| 618 | ||||
| 619 | inline jint jint_cast (jfloat x) { return ((FloatIntConv*)&x)->i; } | |||
| 620 | inline jfloat jfloat_cast (jint x) { return ((FloatIntConv*)&x)->f; } | |||
| 621 | ||||
| 622 | inline jlong jlong_cast (jdouble x) { return ((DoubleLongConv*)&x)->l; } | |||
| 623 | inline julong julong_cast (jdouble x) { return ((DoubleLongConv*)&x)->ul; } | |||
| 624 | inline jdouble jdouble_cast (jlong x) { return ((DoubleLongConv*)&x)->d; } | |||
| 625 | ||||
| 626 | inline jint low (jlong value) { return jint(value); } | |||
| 627 | inline jint high(jlong value) { return jint(value >> 32); } | |||
| 628 | ||||
| 629 | // the fancy casts are a hopefully portable way | |||
| 630 | // to do unsigned 32 to 64 bit type conversion | |||
| 631 | inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32; | |||
| 632 | *value |= (jlong)(julong)(juint)low; } | |||
| 633 | ||||
| 634 | inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff; | |||
| 635 | *value |= (jlong)high << 32; } | |||
| 636 | ||||
| 637 | inline jlong jlong_from(jint h, jint l) { | |||
| 638 | jlong result = 0; // initialization to avoid warning | |||
| 639 | set_high(&result, h); | |||
| 640 | set_low(&result, l); | |||
| 641 | return result; | |||
| 642 | } | |||
| 643 | ||||
| 644 | union jlong_accessor { | |||
| 645 | jint words[2]; | |||
| 646 | jlong long_value; | |||
| 647 | }; | |||
| 648 | ||||
| 649 | void basic_types_init(); // cannot define here; uses assert | |||
| 650 | ||||
| 651 | ||||
| 652 | // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java | |||
| 653 | enum BasicType { | |||
| 654 | // The values T_BOOLEAN..T_LONG (4..11) are derived from the JVMS. | |||
| 655 | T_BOOLEAN = JVM_T_BOOLEAN, | |||
| 656 | T_CHAR = JVM_T_CHAR, | |||
| 657 | T_FLOAT = JVM_T_FLOAT, | |||
| 658 | T_DOUBLE = JVM_T_DOUBLE, | |||
| 659 | T_BYTE = JVM_T_BYTE, | |||
| 660 | T_SHORT = JVM_T_SHORT, | |||
| 661 | T_INT = JVM_T_INT, | |||
| 662 | T_LONG = JVM_T_LONG, | |||
| 663 | // The remaining values are not part of any standard. | |||
| 664 | // T_OBJECT and T_VOID denote two more semantic choices | |||
| 665 | // for method return values. | |||
| 666 | // T_OBJECT and T_ARRAY describe signature syntax. | |||
| 667 | // T_ADDRESS, T_METADATA, T_NARROWOOP, T_NARROWKLASS describe | |||
| 668 | // internal references within the JVM as if they were Java | |||
| 669 | // types in their own right. | |||
| 670 | T_OBJECT = 12, | |||
| 671 | T_ARRAY = 13, | |||
| 672 | T_VOID = 14, | |||
| 673 | T_ADDRESS = 15, | |||
| 674 | T_NARROWOOP = 16, | |||
| 675 | T_METADATA = 17, | |||
| 676 | T_NARROWKLASS = 18, | |||
| 677 | T_CONFLICT = 19, // for stack value type with conflicting contents | |||
| 678 | T_ILLEGAL = 99 | |||
| 679 | }; | |||
| 680 | ||||
| 681 | #define SIGNATURE_TYPES_DO(F, N)F(JVM_SIGNATURE_BOOLEAN, T_BOOLEAN, N) F(JVM_SIGNATURE_CHAR, T_CHAR , N) F(JVM_SIGNATURE_FLOAT, T_FLOAT, N) F(JVM_SIGNATURE_DOUBLE , T_DOUBLE, N) F(JVM_SIGNATURE_BYTE, T_BYTE, N) F(JVM_SIGNATURE_SHORT , T_SHORT, N) F(JVM_SIGNATURE_INT, T_INT, N) F(JVM_SIGNATURE_LONG , T_LONG, N) F(JVM_SIGNATURE_CLASS, T_OBJECT, N) F(JVM_SIGNATURE_ARRAY , T_ARRAY, N) F(JVM_SIGNATURE_VOID, T_VOID, N) \ | |||
| 682 | F(JVM_SIGNATURE_BOOLEAN, T_BOOLEAN, N) \ | |||
| 683 | F(JVM_SIGNATURE_CHAR, T_CHAR, N) \ | |||
| 684 | F(JVM_SIGNATURE_FLOAT, T_FLOAT, N) \ | |||
| 685 | F(JVM_SIGNATURE_DOUBLE, T_DOUBLE, N) \ | |||
| 686 | F(JVM_SIGNATURE_BYTE, T_BYTE, N) \ | |||
| 687 | F(JVM_SIGNATURE_SHORT, T_SHORT, N) \ | |||
| 688 | F(JVM_SIGNATURE_INT, T_INT, N) \ | |||
| 689 | F(JVM_SIGNATURE_LONG, T_LONG, N) \ | |||
| 690 | F(JVM_SIGNATURE_CLASS, T_OBJECT, N) \ | |||
| 691 | F(JVM_SIGNATURE_ARRAY, T_ARRAY, N) \ | |||
| 692 | F(JVM_SIGNATURE_VOID, T_VOID, N) \ | |||
| 693 | /*end*/ | |||
| 694 | ||||
| 695 | inline bool is_java_type(BasicType t) { | |||
| 696 | return T_BOOLEAN <= t && t <= T_VOID; | |||
| 697 | } | |||
| 698 | ||||
| 699 | inline bool is_java_primitive(BasicType t) { | |||
| 700 | return T_BOOLEAN <= t && t <= T_LONG; | |||
| 701 | } | |||
| 702 | ||||
| 703 | inline bool is_subword_type(BasicType t) { | |||
| 704 | // these guys are processed exactly like T_INT in calling sequences: | |||
| 705 | return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT); | |||
| 706 | } | |||
| 707 | ||||
| 708 | inline bool is_signed_subword_type(BasicType t) { | |||
| 709 | return (t == T_BYTE || t == T_SHORT); | |||
| 710 | } | |||
| 711 | ||||
| 712 | inline bool is_double_word_type(BasicType t) { | |||
| 713 | return (t == T_DOUBLE || t == T_LONG); | |||
| 714 | } | |||
| 715 | ||||
| 716 | inline bool is_reference_type(BasicType t) { | |||
| 717 | return (t == T_OBJECT || t == T_ARRAY); | |||
| 718 | } | |||
| 719 | ||||
| 720 | inline bool is_integral_type(BasicType t) { | |||
| 721 | return is_subword_type(t) || t == T_INT || t == T_LONG; | |||
| 722 | } | |||
| 723 | ||||
| 724 | inline bool is_floating_point_type(BasicType t) { | |||
| 725 | return (t == T_FLOAT || t == T_DOUBLE); | |||
| 726 | } | |||
| 727 | ||||
| 728 | extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar | |||
| 729 | inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; } | |||
| 730 | extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements | |||
| 731 | extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar | |||
| 732 | inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL__null; } | |||
| 733 | extern BasicType name2type(const char* name); | |||
| 734 | ||||
| 735 | inline jlong max_signed_integer(BasicType bt) { | |||
| 736 | if (bt == T_INT) { | |||
| 737 | return max_jint; | |||
| 738 | } | |||
| 739 | assert(bt == T_LONG, "unsupported")do { if (!(bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 739, "assert(" "bt == T_LONG" ") failed", "unsupported"); :: breakpoint(); } } while (0); | |||
| 740 | return max_jlong; | |||
| 741 | } | |||
| 742 | ||||
| 743 | inline jlong min_signed_integer(BasicType bt) { | |||
| 744 | if (bt == T_INT) { | |||
| 745 | return min_jint; | |||
| 746 | } | |||
| 747 | assert(bt == T_LONG, "unsupported")do { if (!(bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 747, "assert(" "bt == T_LONG" ") failed", "unsupported"); :: breakpoint(); } } while (0); | |||
| 748 | return min_jlong; | |||
| 749 | } | |||
| 750 | ||||
| 751 | // Auxiliary math routines | |||
| 752 | // least common multiple | |||
| 753 | extern size_t lcm(size_t a, size_t b); | |||
| 754 | ||||
| 755 | ||||
| 756 | // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java | |||
| 757 | enum BasicTypeSize { | |||
| 758 | T_BOOLEAN_size = 1, | |||
| 759 | T_CHAR_size = 1, | |||
| 760 | T_FLOAT_size = 1, | |||
| 761 | T_DOUBLE_size = 2, | |||
| 762 | T_BYTE_size = 1, | |||
| 763 | T_SHORT_size = 1, | |||
| 764 | T_INT_size = 1, | |||
| 765 | T_LONG_size = 2, | |||
| 766 | T_OBJECT_size = 1, | |||
| 767 | T_ARRAY_size = 1, | |||
| 768 | T_NARROWOOP_size = 1, | |||
| 769 | T_NARROWKLASS_size = 1, | |||
| 770 | T_VOID_size = 0 | |||
| 771 | }; | |||
| 772 | ||||
| 773 | // this works on valid parameter types but not T_VOID, T_CONFLICT, etc. | |||
| 774 | inline int parameter_type_word_count(BasicType t) { | |||
| 775 | if (is_double_word_type(t)) return 2; | |||
| 776 | assert(is_java_primitive(t) || is_reference_type(t), "no goofy types here please")do { if (!(is_java_primitive(t) || is_reference_type(t))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 776, "assert(" "is_java_primitive(t) || is_reference_type(t)" ") failed", "no goofy types here please"); ::breakpoint(); } } while (0); | |||
| 777 | assert(type2size[t] == 1, "must be")do { if (!(type2size[t] == 1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 777, "assert(" "type2size[t] == 1" ") failed", "must be"); :: breakpoint(); } } while (0); | |||
| 778 | return 1; | |||
| 779 | } | |||
| 780 | ||||
| 781 | // maps a BasicType to its instance field storage type: | |||
| 782 | // all sub-word integral types are widened to T_INT | |||
| 783 | extern BasicType type2field[T_CONFLICT+1]; | |||
| 784 | extern BasicType type2wfield[T_CONFLICT+1]; | |||
| 785 | ||||
| 786 | ||||
| 787 | // size in bytes | |||
| 788 | enum ArrayElementSize { | |||
| 789 | T_BOOLEAN_aelem_bytes = 1, | |||
| 790 | T_CHAR_aelem_bytes = 2, | |||
| 791 | T_FLOAT_aelem_bytes = 4, | |||
| 792 | T_DOUBLE_aelem_bytes = 8, | |||
| 793 | T_BYTE_aelem_bytes = 1, | |||
| 794 | T_SHORT_aelem_bytes = 2, | |||
| 795 | T_INT_aelem_bytes = 4, | |||
| 796 | T_LONG_aelem_bytes = 8, | |||
| 797 | #ifdef _LP641 | |||
| 798 | T_OBJECT_aelem_bytes = 8, | |||
| 799 | T_ARRAY_aelem_bytes = 8, | |||
| 800 | #else | |||
| 801 | T_OBJECT_aelem_bytes = 4, | |||
| 802 | T_ARRAY_aelem_bytes = 4, | |||
| 803 | #endif | |||
| 804 | T_NARROWOOP_aelem_bytes = 4, | |||
| 805 | T_NARROWKLASS_aelem_bytes = 4, | |||
| 806 | T_VOID_aelem_bytes = 0 | |||
| 807 | }; | |||
| 808 | ||||
| 809 | extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element | |||
| 810 | #ifdef ASSERT1 | |||
| 811 | extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts | |||
| 812 | #else | |||
| 813 | inline int type2aelembytes(BasicType t, bool allow_address = false) { return _type2aelembytes[t]; } | |||
| 814 | #endif | |||
| 815 | ||||
| 816 | ||||
| 817 | // JavaValue serves as a container for arbitrary Java values. | |||
| 818 | ||||
| 819 | class JavaValue { | |||
| 820 | ||||
| 821 | public: | |||
| 822 | typedef union JavaCallValue { | |||
| 823 | jfloat f; | |||
| 824 | jdouble d; | |||
| 825 | jint i; | |||
| 826 | jlong l; | |||
| 827 | jobject h; | |||
| 828 | oopDesc* o; | |||
| 829 | } JavaCallValue; | |||
| 830 | ||||
| 831 | private: | |||
| 832 | BasicType _type; | |||
| 833 | JavaCallValue _value; | |||
| 834 | ||||
| 835 | public: | |||
| 836 | JavaValue(BasicType t = T_ILLEGAL) { _type = t; } | |||
| 837 | ||||
| 838 | JavaValue(jfloat value) { | |||
| 839 | _type = T_FLOAT; | |||
| 840 | _value.f = value; | |||
| 841 | } | |||
| 842 | ||||
| 843 | JavaValue(jdouble value) { | |||
| 844 | _type = T_DOUBLE; | |||
| 845 | _value.d = value; | |||
| 846 | } | |||
| 847 | ||||
| 848 | jfloat get_jfloat() const { return _value.f; } | |||
| 849 | jdouble get_jdouble() const { return _value.d; } | |||
| 850 | jint get_jint() const { return _value.i; } | |||
| 851 | jlong get_jlong() const { return _value.l; } | |||
| 852 | jobject get_jobject() const { return _value.h; } | |||
| 853 | oopDesc* get_oop() const { return _value.o; } | |||
| 854 | JavaCallValue* get_value_addr() { return &_value; } | |||
| 855 | BasicType get_type() const { return _type; } | |||
| 856 | ||||
| 857 | void set_jfloat(jfloat f) { _value.f = f;} | |||
| 858 | void set_jdouble(jdouble d) { _value.d = d;} | |||
| 859 | void set_jint(jint i) { _value.i = i;} | |||
| 860 | void set_jlong(jlong l) { _value.l = l;} | |||
| 861 | void set_jobject(jobject h) { _value.h = h;} | |||
| 862 | void set_oop(oopDesc* o) { _value.o = o;} | |||
| 863 | void set_type(BasicType t) { _type = t; } | |||
| 864 | ||||
| 865 | jboolean get_jboolean() const { return (jboolean) (_value.i);} | |||
| 866 | jbyte get_jbyte() const { return (jbyte) (_value.i);} | |||
| 867 | jchar get_jchar() const { return (jchar) (_value.i);} | |||
| 868 | jshort get_jshort() const { return (jshort) (_value.i);} | |||
| 869 | ||||
| 870 | }; | |||
| 871 | ||||
| 872 | ||||
| 873 | // TosState describes the top-of-stack state before and after the execution of | |||
| 874 | // a bytecode or method. The top-of-stack value may be cached in one or more CPU | |||
| 875 | // registers. The TosState corresponds to the 'machine representation' of this cached | |||
| 876 | // value. There's 4 states corresponding to the JAVA types int, long, float & double | |||
| 877 | // as well as a 5th state in case the top-of-stack value is actually on the top | |||
| 878 | // of stack (in memory) and thus not cached. The atos state corresponds to the itos | |||
| 879 | // state when it comes to machine representation but is used separately for (oop) | |||
| 880 | // type specific operations (e.g. verification code). | |||
| 881 | ||||
| 882 | enum TosState { // describes the tos cache contents | |||
| 883 | btos = 0, // byte, bool tos cached | |||
| 884 | ztos = 1, // byte, bool tos cached | |||
| 885 | ctos = 2, // char tos cached | |||
| 886 | stos = 3, // short tos cached | |||
| 887 | itos = 4, // int tos cached | |||
| 888 | ltos = 5, // long tos cached | |||
| 889 | ftos = 6, // float tos cached | |||
| 890 | dtos = 7, // double tos cached | |||
| 891 | atos = 8, // object cached | |||
| 892 | vtos = 9, // tos not cached | |||
| 893 | number_of_states, | |||
| 894 | ilgl // illegal state: should not occur | |||
| 895 | }; | |||
| 896 | ||||
| 897 | ||||
| 898 | inline TosState as_TosState(BasicType type) { | |||
| 899 | switch (type) { | |||
| 900 | case T_BYTE : return btos; | |||
| 901 | case T_BOOLEAN: return ztos; | |||
| 902 | case T_CHAR : return ctos; | |||
| 903 | case T_SHORT : return stos; | |||
| 904 | case T_INT : return itos; | |||
| 905 | case T_LONG : return ltos; | |||
| 906 | case T_FLOAT : return ftos; | |||
| 907 | case T_DOUBLE : return dtos; | |||
| 908 | case T_VOID : return vtos; | |||
| 909 | case T_ARRAY : // fall through | |||
| 910 | case T_OBJECT : return atos; | |||
| 911 | default : return ilgl; | |||
| 912 | } | |||
| 913 | } | |||
| 914 | ||||
| 915 | inline BasicType as_BasicType(TosState state) { | |||
| 916 | switch (state) { | |||
| 917 | case btos : return T_BYTE; | |||
| 918 | case ztos : return T_BOOLEAN; | |||
| 919 | case ctos : return T_CHAR; | |||
| 920 | case stos : return T_SHORT; | |||
| 921 | case itos : return T_INT; | |||
| 922 | case ltos : return T_LONG; | |||
| 923 | case ftos : return T_FLOAT; | |||
| 924 | case dtos : return T_DOUBLE; | |||
| 925 | case atos : return T_OBJECT; | |||
| 926 | case vtos : return T_VOID; | |||
| 927 | default : return T_ILLEGAL; | |||
| 928 | } | |||
| 929 | } | |||
| 930 | ||||
| 931 | ||||
| 932 | // Helper function to convert BasicType info into TosState | |||
| 933 | // Note: Cannot define here as it uses global constant at the time being. | |||
| 934 | TosState as_TosState(BasicType type); | |||
| 935 | ||||
| 936 | ||||
| 937 | // JavaThreadState keeps track of which part of the code a thread is executing in. This | |||
| 938 | // information is needed by the safepoint code. | |||
| 939 | // | |||
| 940 | // There are 4 essential states: | |||
| 941 | // | |||
| 942 | // _thread_new : Just started, but not executed init. code yet (most likely still in OS init code) | |||
| 943 | // _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles | |||
| 944 | // _thread_in_vm : Executing in the vm | |||
| 945 | // _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub) | |||
| 946 | // | |||
| 947 | // Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in | |||
| 948 | // a transition from one state to another. These extra states makes it possible for the safepoint code to | |||
| 949 | // handle certain thread_states without having to suspend the thread - making the safepoint code faster. | |||
| 950 | // | |||
| 951 | // Given a state, the xxxx_trans state can always be found by adding 1. | |||
| 952 | // | |||
| 953 | enum JavaThreadState { | |||
| 954 | _thread_uninitialized = 0, // should never happen (missing initialization) | |||
| 955 | _thread_new = 2, // just starting up, i.e., in process of being initialized | |||
| 956 | _thread_new_trans = 3, // corresponding transition state (not used, included for completness) | |||
| 957 | _thread_in_native = 4, // running in native code | |||
| 958 | _thread_in_native_trans = 5, // corresponding transition state | |||
| 959 | _thread_in_vm = 6, // running in VM | |||
| 960 | _thread_in_vm_trans = 7, // corresponding transition state | |||
| 961 | _thread_in_Java = 8, // running in Java or in stub code | |||
| 962 | _thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness) | |||
| 963 | _thread_blocked = 10, // blocked in vm | |||
| 964 | _thread_blocked_trans = 11, // corresponding transition state | |||
| 965 | _thread_max_state = 12 // maximum thread state+1 - used for statistics allocation | |||
| 966 | }; | |||
| 967 | ||||
| 968 | //---------------------------------------------------------------------------------------------------- | |||
| 969 | // Special constants for debugging | |||
| 970 | ||||
| 971 | const jint badInt = -3; // generic "bad int" value | |||
| 972 | const intptr_t badAddressVal = -2; // generic "bad address" value | |||
| 973 | const intptr_t badOopVal = -1; // generic "bad oop" value | |||
| 974 | const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE)(0x2BAD4B0BBAADBABELL); // value used to zap heap after GC | |||
| 975 | const int badStackSegVal = 0xCA; // value used to zap stack segments | |||
| 976 | const int badHandleValue = 0xBC; // value used to zap vm handle area | |||
| 977 | const int badResourceValue = 0xAB; // value used to zap resource area | |||
| 978 | const int freeBlockPad = 0xBA; // value used to pad freed blocks. | |||
| 979 | const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks. | |||
| 980 | const juint uninitMetaWordVal= 0xf7f7f7f7; // value used to zap newly allocated metachunk | |||
| 981 | const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC | |||
| 982 | const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC | |||
| 983 | const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation | |||
| 984 | const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation | |||
| 985 | ||||
| 986 | ||||
| 987 | // (These must be implemented as #defines because C++ compilers are | |||
| 988 | // not obligated to inline non-integral constants!) | |||
| 989 | #define badAddress((address)::badAddressVal) ((address)::badAddressVal) | |||
| 990 | #define badOop(cast_to_oop(::badOopVal)) (cast_to_oop(::badOopVal)) | |||
| 991 | #define badHeapWord(::badHeapWordVal) (::badHeapWordVal) | |||
| 992 | ||||
| 993 | // Default TaskQueue size is 16K (32-bit) or 128K (64-bit) | |||
| 994 | #define TASKQUEUE_SIZE( 1<<17) (NOT_LP64(1<<14) LP64_ONLY(1<<17)1<<17) | |||
| 995 | ||||
| 996 | //---------------------------------------------------------------------------------------------------- | |||
| 997 | // Utility functions for bitfield manipulations | |||
| 998 | ||||
| 999 | const intptr_t AllBits = ~0; // all bits set in a word | |||
| 1000 | const intptr_t NoBits = 0; // no bits set in a word | |||
| 1001 | const jlong NoLongBits = 0; // no bits set in a long | |||
| 1002 | const intptr_t OneBit = 1; // only right_most bit set in a word | |||
| 1003 | ||||
| 1004 | // get a word with the n.th or the right-most or left-most n bits set | |||
| 1005 | // (note: #define used only so that they can be used in enum constant definitions) | |||
| 1006 | #define nth_bit(n)(((n) >= BitsPerWord) ? 0 : (OneBit << (n))) (((n) >= BitsPerWord) ? 0 : (OneBit << (n))) | |||
| 1007 | #define right_n_bits(n)((((n) >= BitsPerWord) ? 0 : (OneBit << (n))) - 1) (nth_bit(n)(((n) >= BitsPerWord) ? 0 : (OneBit << (n))) - 1) | |||
| 1008 | ||||
| 1009 | // bit-operations using a mask m | |||
| 1010 | inline void set_bits (intptr_t& x, intptr_t m) { x |= m; } | |||
| 1011 | inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; } | |||
| 1012 | inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; } | |||
| 1013 | inline jlong mask_long_bits (jlong x, jlong m) { return x & m; } | |||
| 1014 | inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; } | |||
| 1015 | ||||
| 1016 | // bit-operations using the n.th bit | |||
| 1017 | inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)(((n) >= BitsPerWord) ? 0 : (OneBit << (n)))); } | |||
| 1018 | inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)(((n) >= BitsPerWord) ? 0 : (OneBit << (n)))); } | |||
| 1019 | inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)(((n) >= BitsPerWord) ? 0 : (OneBit << (n)))) != NoBits; } | |||
| 1020 | ||||
| 1021 | // returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!) | |||
| 1022 | inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) { | |||
| 1023 | return mask_bits(x >> start_bit_no, right_n_bits(field_length)((((field_length) >= BitsPerWord) ? 0 : (OneBit << ( field_length))) - 1)); | |||
| 1024 | } | |||
| 1025 | ||||
| 1026 | ||||
| 1027 | //---------------------------------------------------------------------------------------------------- | |||
| 1028 | // Utility functions for integers | |||
| 1029 | ||||
| 1030 | // Avoid use of global min/max macros which may cause unwanted double | |||
| 1031 | // evaluation of arguments. | |||
| 1032 | #ifdef max | |||
| 1033 | #undef max | |||
| 1034 | #endif | |||
| 1035 | ||||
| 1036 | #ifdef min | |||
| 1037 | #undef min | |||
| 1038 | #endif | |||
| 1039 | ||||
| 1040 | // It is necessary to use templates here. Having normal overloaded | |||
| 1041 | // functions does not work because it is necessary to provide both 32- | |||
| 1042 | // and 64-bit overloaded functions, which does not work, and having | |||
| 1043 | // explicitly-typed versions of these routines (i.e., MAX2I, MAX2L) | |||
| 1044 | // will be even more error-prone than macros. | |||
| 1045 | template<class T> constexpr T MAX2(T a, T b) { return (a > b) ? a : b; } | |||
| 1046 | template<class T> constexpr T MIN2(T a, T b) { return (a < b) ? a : b; } | |||
| 1047 | template<class T> constexpr T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); } | |||
| 1048 | template<class T> constexpr T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); } | |||
| 1049 | template<class T> constexpr T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } | |||
| 1050 | template<class T> constexpr T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); } | |||
| 1051 | ||||
| 1052 | template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; } | |||
| 1053 | ||||
| 1054 | // Return the given value clamped to the range [min ... max] | |||
| 1055 | template<typename T> | |||
| 1056 | inline T clamp(T value, T min, T max) { | |||
| 1057 | assert(min <= max, "must be")do { if (!(min <= max)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/utilities/globalDefinitions.hpp" , 1057, "assert(" "min <= max" ") failed", "must be"); ::breakpoint (); } } while (0); | |||
| 1058 | return MIN2(MAX2(value, min), max); | |||
| 1059 | } | |||
| 1060 | ||||
| 1061 | inline bool is_odd (intx x) { return x & 1; } | |||
| 1062 | inline bool is_even(intx x) { return !is_odd(x); } | |||
| 1063 | ||||
| 1064 | // abs methods which cannot overflow and so are well-defined across | |||
| 1065 | // the entire domain of integer types. | |||
| 1066 | static inline unsigned int uabs(unsigned int n) { | |||
| 1067 | union { | |||
| 1068 | unsigned int result; | |||
| 1069 | int value; | |||
| 1070 | }; | |||
| 1071 | result = n; | |||
| 1072 | if (value < 0) result = 0-result; | |||
| 1073 | return result; | |||
| 1074 | } | |||
| 1075 | static inline julong uabs(julong n) { | |||
| 1076 | union { | |||
| 1077 | julong result; | |||
| 1078 | jlong value; | |||
| 1079 | }; | |||
| 1080 | result = n; | |||
| 1081 | if (value < 0) result = 0-result; | |||
| 1082 | return result; | |||
| 1083 | } | |||
| 1084 | static inline julong uabs(jlong n) { return uabs((julong)n); } | |||
| 1085 | static inline unsigned int uabs(int n) { return uabs((unsigned int)n); } | |||
| 1086 | ||||
| 1087 | // "to" should be greater than "from." | |||
| 1088 | inline intx byte_size(void* from, void* to) { | |||
| 1089 | return (address)to - (address)from; | |||
| 1090 | } | |||
| 1091 | ||||
| 1092 | ||||
| 1093 | // Pack and extract shorts to/from ints: | |||
| 1094 | ||||
| 1095 | inline int extract_low_short_from_int(jint x) { | |||
| 1096 | return x & 0xffff; | |||
| 1097 | } | |||
| 1098 | ||||
| 1099 | inline int extract_high_short_from_int(jint x) { | |||
| 1100 | return (x >> 16) & 0xffff; | |||
| 1101 | } | |||
| 1102 | ||||
| 1103 | inline int build_int_from_shorts( jushort low, jushort high ) { | |||
| 1104 | return ((int)((unsigned int)high << 16) | (unsigned int)low); | |||
| 1105 | } | |||
| 1106 | ||||
| 1107 | // swap a & b | |||
| 1108 | template<class T> static void swap(T& a, T& b) { | |||
| 1109 | T tmp = a; | |||
| 1110 | a = b; | |||
| 1111 | b = tmp; | |||
| 1112 | } | |||
| 1113 | ||||
| 1114 | // array_size_impl is a function that takes a reference to T[N] and | |||
| 1115 | // returns a reference to char[N]. It is not ODR-used, so not defined. | |||
| 1116 | template<typename T, size_t N> char (&array_size_impl(T (&)[N]))[N]; | |||
| 1117 | ||||
| 1118 | #define ARRAY_SIZE(array)sizeof(array_size_impl(array)) sizeof(array_size_impl(array)) | |||
| 1119 | ||||
| 1120 | //---------------------------------------------------------------------------------------------------- | |||
| 1121 | // Sum and product which can never overflow: they wrap, just like the | |||
| 1122 | // Java operations. Note that we don't intend these to be used for | |||
| 1123 | // general-purpose arithmetic: their purpose is to emulate Java | |||
| 1124 | // operations. | |||
| 1125 | ||||
| 1126 | // The goal of this code to avoid undefined or implementation-defined | |||
| 1127 | // behavior. The use of an lvalue to reference cast is explicitly | |||
| 1128 | // permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para | |||
| 1129 | // 15 in C++03] | |||
| 1130 | #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \ | |||
| 1131 | inline TYPE NAME (TYPE in1, TYPE in2) { \ | |||
| 1132 | UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \ | |||
| 1133 | ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \ | |||
| 1134 | return reinterpret_cast<TYPE&>(ures); \ | |||
| 1135 | } | |||
| 1136 | ||||
| 1137 | JAVA_INTEGER_OP(+, java_add, jint, juint) | |||
| 1138 | JAVA_INTEGER_OP(-, java_subtract, jint, juint) | |||
| 1139 | JAVA_INTEGER_OP(*, java_multiply, jint, juint) | |||
| 1140 | JAVA_INTEGER_OP(+, java_add, jlong, julong) | |||
| 1141 | JAVA_INTEGER_OP(-, java_subtract, jlong, julong) | |||
| 1142 | JAVA_INTEGER_OP(*, java_multiply, jlong, julong) | |||
| 1143 | ||||
| 1144 | #undef JAVA_INTEGER_OP | |||
| 1145 | ||||
| 1146 | // Provide integer shift operations with Java semantics. No overflow | |||
| 1147 | // issues - left shifts simply discard shifted out bits. No undefined | |||
| 1148 | // behavior for large or negative shift quantities; instead the actual | |||
| 1149 | // shift distance is the argument modulo the lhs value's size in bits. | |||
| 1150 | // No undefined or implementation defined behavior for shifting negative | |||
| 1151 | // values; left shift discards bits, right shift sign extends. We use | |||
| 1152 | // the same safe conversion technique as above for java_add and friends. | |||
| 1153 | #define JAVA_INTEGER_SHIFT_OP(OP, NAME, TYPE, XTYPE) \ | |||
| 1154 | inline TYPE NAME (TYPE lhs, jint rhs) { \ | |||
| 1155 | const uint rhs_mask = (sizeof(TYPE) * 8) - 1; \ | |||
| 1156 | STATIC_ASSERT(rhs_mask == 31 || rhs_mask == 63)static_assert((rhs_mask == 31 || rhs_mask == 63), "rhs_mask == 31 || rhs_mask == 63" ); \ | |||
| 1157 | XTYPE xres = static_cast<XTYPE>(lhs); \ | |||
| 1158 | xres OP ## = (rhs & rhs_mask); \ | |||
| 1159 | return reinterpret_cast<TYPE&>(xres); \ | |||
| 1160 | } | |||
| 1161 | ||||
| 1162 | JAVA_INTEGER_SHIFT_OP(<<, java_shift_left, jint, juint) | |||
| 1163 | JAVA_INTEGER_SHIFT_OP(<<, java_shift_left, jlong, julong) | |||
| 1164 | // For signed shift right, assume C++ implementation >> sign extends. | |||
| 1165 | JAVA_INTEGER_SHIFT_OP(>>, java_shift_right, jint, jint) | |||
| 1166 | JAVA_INTEGER_SHIFT_OP(>>, java_shift_right, jlong, jlong) | |||
| 1167 | // For >>> use C++ unsigned >>. | |||
| 1168 | JAVA_INTEGER_SHIFT_OP(>>, java_shift_right_unsigned, jint, juint) | |||
| 1169 | JAVA_INTEGER_SHIFT_OP(>>, java_shift_right_unsigned, jlong, julong) | |||
| 1170 | ||||
| 1171 | #undef JAVA_INTEGER_SHIFT_OP | |||
| 1172 | ||||
| 1173 | //---------------------------------------------------------------------------------------------------- | |||
| 1174 | // The goal of this code is to provide saturating operations for int/uint. | |||
| 1175 | // Checks overflow conditions and saturates the result to min_jint/max_jint. | |||
| 1176 | #define SATURATED_INTEGER_OP(OP, NAME, TYPE1, TYPE2) \ | |||
| 1177 | inline int NAME (TYPE1 in1, TYPE2 in2) { \ | |||
| 1178 | jlong res = static_cast<jlong>(in1); \ | |||
| 1179 | res OP ## = static_cast<jlong>(in2); \ | |||
| 1180 | if (res > max_jint) { \ | |||
| 1181 | res = max_jint; \ | |||
| 1182 | } else if (res < min_jint) { \ | |||
| 1183 | res = min_jint; \ | |||
| 1184 | } \ | |||
| 1185 | return static_cast<int>(res); \ | |||
| 1186 | } | |||
| 1187 | ||||
| 1188 | SATURATED_INTEGER_OP(+, saturated_add, int, int) | |||
| 1189 | SATURATED_INTEGER_OP(+, saturated_add, int, uint) | |||
| 1190 | SATURATED_INTEGER_OP(+, saturated_add, uint, int) | |||
| 1191 | SATURATED_INTEGER_OP(+, saturated_add, uint, uint) | |||
| 1192 | ||||
| 1193 | #undef SATURATED_INTEGER_OP | |||
| 1194 | ||||
| 1195 | // Dereference vptr | |||
| 1196 | // All C++ compilers that we know of have the vtbl pointer in the first | |||
| 1197 | // word. If there are exceptions, this function needs to be made compiler | |||
| 1198 | // specific. | |||
| 1199 | static inline void* dereference_vptr(const void* addr) { | |||
| 1200 | return *(void**)addr; | |||
| ||||
| 1201 | } | |||
| 1202 | ||||
| 1203 | //---------------------------------------------------------------------------------------------------- | |||
| 1204 | // String type aliases used by command line flag declarations and | |||
| 1205 | // processing utilities. | |||
| 1206 | ||||
| 1207 | typedef const char* ccstr; | |||
| 1208 | typedef const char* ccstrlist; // represents string arguments which accumulate | |||
| 1209 | ||||
| 1210 | //---------------------------------------------------------------------------------------------------- | |||
| 1211 | // Default hash/equals functions used by ResourceHashtable | |||
| 1212 | ||||
| 1213 | template<typename K> unsigned primitive_hash(const K& k) { | |||
| 1214 | unsigned hash = (unsigned)((uintptr_t)k); | |||
| 1215 | return hash ^ (hash >> 3); // just in case we're dealing with aligned ptrs | |||
| 1216 | } | |||
| 1217 | ||||
| 1218 | template<typename K> bool primitive_equals(const K& k0, const K& k1) { | |||
| 1219 | return k0 == k1; | |||
| 1220 | } | |||
| 1221 | ||||
| 1222 | ||||
| 1223 | #endif // SHARE_UTILITIES_GLOBALDEFINITIONS_HPP |