8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderDataGraph.hpp"
27 #include "classfile/metadataOnStackMark.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/debugInfoRec.hpp"
31 #include "compiler/compilationPolicy.hpp"
32 #include "gc/shared/collectedHeap.inline.hpp"
33 #include "interpreter/bytecodeStream.hpp"
34 #include "interpreter/bytecodeTracer.hpp"
35 #include "interpreter/bytecodes.hpp"
36 #include "interpreter/interpreter.hpp"
37 #include "interpreter/oopMapCache.hpp"
38 #include "memory/allocation.inline.hpp"
39 #include "memory/heapInspection.hpp"
40 #include "memory/metadataFactory.hpp"
41 #include "memory/metaspaceClosure.hpp"
42 #include "memory/metaspaceShared.hpp"
43 #include "memory/oopFactory.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "memory/universe.hpp"
46 #include "oops/constMethod.hpp"
47 #include "oops/constantPool.hpp"
361 } else {
362 _vtable_index = index;
363 }
364 }
365
366 void Method::set_itable_index(int index) {
367 if (is_shared() && !MetaspaceShared::remapped_readwrite()) {
368 // At runtime initialize_itable is rerun as part of link_class_impl()
369 // for a shared class loaded by the non-boot loader to obtain the loader
370 // constraints based on the runtime classloaders' context. The dumptime
371 // itable index should be the same as the runtime index.
372 assert(_vtable_index == itable_index_max - index,
373 "archived itable index is different from runtime index");
374 return; // don’t write into the shared class
375 } else {
376 _vtable_index = itable_index_max - index;
377 }
378 assert(valid_itable_index(), "");
379 }
380
381
382
383 bool Method::was_executed_more_than(int n) {
384 // Invocation counter is reset when the Method* is compiled.
385 // If the method has compiled code we therefore assume it has
386 // be excuted more than n times.
387 if (is_accessor() || is_empty_method() || (code() != NULL)) {
388 // interpreter doesn't bump invocation counter of trivial methods
389 // compiler does not bump invocation counter of compiled methods
390 return true;
391 }
392 else if ((method_counters() != NULL &&
393 method_counters()->invocation_counter()->carry()) ||
394 (method_data() != NULL &&
395 method_data()->invocation_counter()->carry())) {
396 // The carry bit is set when the counter overflows and causes
397 // a compilation to occur. We don't know how many times
398 // the counter has been reset, so we simply assume it has
399 // been executed more than n times.
400 return true;
401 } else {
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderDataGraph.hpp"
27 #include "classfile/metadataOnStackMark.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
30 #include "code/codeCache.hpp"
31 #include "code/debugInfoRec.hpp"
32 #include "compiler/compilationPolicy.hpp"
33 #include "gc/shared/collectedHeap.inline.hpp"
34 #include "interpreter/bytecodeStream.hpp"
35 #include "interpreter/bytecodeTracer.hpp"
36 #include "interpreter/bytecodes.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/oopMapCache.hpp"
39 #include "memory/allocation.inline.hpp"
40 #include "memory/heapInspection.hpp"
41 #include "memory/metadataFactory.hpp"
42 #include "memory/metaspaceClosure.hpp"
43 #include "memory/metaspaceShared.hpp"
44 #include "memory/oopFactory.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "memory/universe.hpp"
47 #include "oops/constMethod.hpp"
48 #include "oops/constantPool.hpp"
362 } else {
363 _vtable_index = index;
364 }
365 }
366
367 void Method::set_itable_index(int index) {
368 if (is_shared() && !MetaspaceShared::remapped_readwrite()) {
369 // At runtime initialize_itable is rerun as part of link_class_impl()
370 // for a shared class loaded by the non-boot loader to obtain the loader
371 // constraints based on the runtime classloaders' context. The dumptime
372 // itable index should be the same as the runtime index.
373 assert(_vtable_index == itable_index_max - index,
374 "archived itable index is different from runtime index");
375 return; // don’t write into the shared class
376 } else {
377 _vtable_index = itable_index_max - index;
378 }
379 assert(valid_itable_index(), "");
380 }
381
382 // The RegisterNatives call being attempted tried to register with a method that
383 // is not native. Ask JVM TI what prefixes have been specified. Then check
384 // to see if the native method is now wrapped with the prefixes. See the
385 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.
386 static Method* find_prefixed_native(Klass* k, Symbol* name, Symbol* signature, TRAPS) {
387 #if INCLUDE_JVMTI
388 ResourceMark rm(THREAD);
389 Method* method;
390 int name_len = name->utf8_length();
391 char* name_str = name->as_utf8();
392 int prefix_count;
393 char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
394 for (int i = 0; i < prefix_count; i++) {
395 char* prefix = prefixes[i];
396 int prefix_len = (int)strlen(prefix);
397
398 // try adding this prefix to the method name and see if it matches another method name
399 int trial_len = name_len + prefix_len;
400 char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
401 strcpy(trial_name_str, prefix);
402 strcat(trial_name_str, name_str);
403 TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len);
404 if (trial_name == NULL) {
405 continue; // no such symbol, so this prefix wasn't used, try the next prefix
406 }
407 method = k->lookup_method(trial_name, signature);
408 if (method == NULL) {
409 continue; // signature doesn't match, try the next prefix
410 }
411 if (method->is_native()) {
412 method->set_is_prefixed_native();
413 return method; // wahoo, we found a prefixed version of the method, return it
414 }
415 // found as non-native, so prefix is good, add it, probably just need more prefixes
416 name_len = trial_len;
417 name_str = trial_name_str;
418 }
419 #endif // INCLUDE_JVMTI
420 return NULL; // not found
421 }
422
423 void Method::register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
424 Method* method = k->lookup_method(name, signature);
425 if (method == NULL) {
426 ResourceMark rm;
427 stringStream st;
428 st.print("Method '");
429 Method::print_external_name(&st, k, name, signature);
430 st.print("' name or signature does not match");
431 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), st.as_string());
432 }
433 if (!method->is_native()) {
434 // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
435 method = find_prefixed_native(k, name, signature, THREAD);
436 if (method == NULL) {
437 ResourceMark rm;
438 stringStream st;
439 st.print("Method '");
440 Method::print_external_name(&st, k, name, signature);
441 st.print("' is not declared as native");
442 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), st.as_string());
443 }
444 }
445
446 if (entry != NULL) {
447 method->set_native_function(entry,
448 Method::native_bind_event_is_interesting);
449 } else {
450 method->clear_native_function();
451 }
452 if (PrintJNIResolving) {
453 ResourceMark rm(THREAD);
454 tty->print_cr("[Registering JNI native method %s.%s]",
455 method->method_holder()->external_name(),
456 method->name()->as_C_string());
457 }
458 }
459
460 bool Method::was_executed_more_than(int n) {
461 // Invocation counter is reset when the Method* is compiled.
462 // If the method has compiled code we therefore assume it has
463 // be excuted more than n times.
464 if (is_accessor() || is_empty_method() || (code() != NULL)) {
465 // interpreter doesn't bump invocation counter of trivial methods
466 // compiler does not bump invocation counter of compiled methods
467 return true;
468 }
469 else if ((method_counters() != NULL &&
470 method_counters()->invocation_counter()->carry()) ||
471 (method_data() != NULL &&
472 method_data()->invocation_counter()->carry())) {
473 // The carry bit is set when the counter overflows and causes
474 // a compilation to occur. We don't know how many times
475 // the counter has been reset, so we simply assume it has
476 // been executed more than n times.
477 return true;
478 } else {
|