38 #include "interpreter/interpreter.hpp"
39 #include "interpreter/interpreterRuntime.hpp"
40 #include "logging/log.hpp"
41 #include "memory/metaspaceShared.hpp"
42 #include "memory/resourceArea.hpp"
43 #include "memory/universe.inline.hpp"
44 #include "oops/klass.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "prims/forte.hpp"
48 #include "prims/jvmtiExport.hpp"
49 #include "prims/methodHandles.hpp"
50 #include "prims/nativeLookup.hpp"
51 #include "runtime/arguments.hpp"
52 #include "runtime/atomic.hpp"
53 #include "runtime/biasedLocking.hpp"
54 #include "runtime/compilationPolicy.hpp"
55 #include "runtime/handles.inline.hpp"
56 #include "runtime/init.hpp"
57 #include "runtime/interfaceSupport.hpp"
58 #include "runtime/javaCalls.hpp"
59 #include "runtime/sharedRuntime.hpp"
60 #include "runtime/stubRoutines.hpp"
61 #include "runtime/vframe.hpp"
62 #include "runtime/vframeArray.hpp"
63 #include "trace/tracing.hpp"
64 #include "utilities/copy.hpp"
65 #include "utilities/dtrace.hpp"
66 #include "utilities/events.hpp"
67 #include "utilities/hashtable.inline.hpp"
68 #include "utilities/macros.hpp"
69 #include "utilities/xmlstream.hpp"
70 #ifdef COMPILER1
71 #include "c1/c1_Runtime1.hpp"
72 #endif
73
74 // Shared stub locations
75 RuntimeStub* SharedRuntime::_wrong_method_blob;
76 RuntimeStub* SharedRuntime::_wrong_method_abstract_blob;
77 RuntimeStub* SharedRuntime::_ic_miss_blob;
1916 src->klass()->copy_array((arrayOopDesc*)src, src_pos,
1917 (arrayOopDesc*)dest, dest_pos,
1918 length, thread);
1919 }
1920 JRT_END
1921
1922 // The caller of generate_class_cast_message() (or one of its callers)
1923 // must use a ResourceMark in order to correctly free the result.
1924 char* SharedRuntime::generate_class_cast_message(
1925 JavaThread* thread, Klass* caster_klass) {
1926
1927 // Get target class name from the checkcast instruction
1928 vframeStream vfst(thread, true);
1929 assert(!vfst.at_end(), "Java frame must exist");
1930 Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
1931 Klass* target_klass = vfst.method()->constants()->klass_at(
1932 cc.index(), thread);
1933 return generate_class_cast_message(caster_klass, target_klass);
1934 }
1935
1936 char* SharedRuntime::generate_class_cast_message(
1937 Klass* caster_klass, Klass* target_klass) {
1938
1939 const char* caster_klass_name = caster_klass->external_name();
1940 Klass* c_klass = caster_klass->is_objArray_klass() ?
1941 ObjArrayKlass::cast(caster_klass)->bottom_klass() : caster_klass;
1942 ModuleEntry* caster_module;
1943 const char* caster_module_name;
1944 if (c_klass->is_instance_klass()) {
1945 caster_module = InstanceKlass::cast(c_klass)->module();
1946 caster_module_name = caster_module->is_named() ?
1947 caster_module->name()->as_C_string() : UNNAMED_MODULE;
1948 } else {
1949 caster_module_name = "java.base";
1950 }
1951 const char* target_klass_name = target_klass->external_name();
1952 Klass* t_klass = target_klass->is_objArray_klass() ?
1953 ObjArrayKlass::cast(target_klass)->bottom_klass() : target_klass;
1954 ModuleEntry* target_module;
1955 const char* target_module_name;
1956 if (t_klass->is_instance_klass()) {
1957 target_module = InstanceKlass::cast(t_klass)->module();
1958 target_module_name = target_module->is_named() ?
1959 target_module->name()->as_C_string(): UNNAMED_MODULE;
1960 } else {
1961 target_module_name = "java.base";
1962 }
1963
1964 size_t msglen = strlen(caster_klass_name) + strlen(caster_module_name) +
1965 strlen(target_klass_name) + strlen(target_module_name) + 50;
1966
1967 char* message = NEW_RESOURCE_ARRAY(char, msglen);
1968 if (NULL == message) {
1969 // Shouldn't happen, but don't cause even more problems if it does
1970 message = const_cast<char*>(caster_klass_name);
1971 } else {
1972 jio_snprintf(message, msglen, "%s (in module: %s) cannot be cast to %s (in module: %s)",
1973 caster_klass_name, caster_module_name, target_klass_name, target_module_name);
1974 }
1975 return message;
1976 }
1977
1978 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
1979 (void) JavaThread::current()->reguard_stack();
1980 JRT_END
1981
1982
1983 // Handles the uncommon case in locking, i.e., contention or an inflated lock.
1984 JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* _obj, BasicLock* lock, JavaThread* thread))
1985 // Disable ObjectSynchronizer::quick_enter() in default config
1986 // on AARCH64 and ARM until JDK-8153107 is resolved.
1987 if (ARM_ONLY((SyncFlags & 256) != 0 &&)
1988 AARCH64_ONLY((SyncFlags & 256) != 0 &&)
1989 !SafepointSynchronize::is_synchronizing()) {
1990 // Only try quick_enter() if we're not trying to reach a safepoint
1991 // so that the calling thread reaches the safepoint more quickly.
1992 if (ObjectSynchronizer::quick_enter(_obj, thread, lock)) return;
1993 }
|
38 #include "interpreter/interpreter.hpp"
39 #include "interpreter/interpreterRuntime.hpp"
40 #include "logging/log.hpp"
41 #include "memory/metaspaceShared.hpp"
42 #include "memory/resourceArea.hpp"
43 #include "memory/universe.inline.hpp"
44 #include "oops/klass.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "prims/forte.hpp"
48 #include "prims/jvmtiExport.hpp"
49 #include "prims/methodHandles.hpp"
50 #include "prims/nativeLookup.hpp"
51 #include "runtime/arguments.hpp"
52 #include "runtime/atomic.hpp"
53 #include "runtime/biasedLocking.hpp"
54 #include "runtime/compilationPolicy.hpp"
55 #include "runtime/handles.inline.hpp"
56 #include "runtime/init.hpp"
57 #include "runtime/interfaceSupport.hpp"
58 #include "runtime/java.hpp"
59 #include "runtime/javaCalls.hpp"
60 #include "runtime/sharedRuntime.hpp"
61 #include "runtime/stubRoutines.hpp"
62 #include "runtime/vframe.hpp"
63 #include "runtime/vframeArray.hpp"
64 #include "trace/tracing.hpp"
65 #include "utilities/copy.hpp"
66 #include "utilities/dtrace.hpp"
67 #include "utilities/events.hpp"
68 #include "utilities/hashtable.inline.hpp"
69 #include "utilities/macros.hpp"
70 #include "utilities/xmlstream.hpp"
71 #ifdef COMPILER1
72 #include "c1/c1_Runtime1.hpp"
73 #endif
74
75 // Shared stub locations
76 RuntimeStub* SharedRuntime::_wrong_method_blob;
77 RuntimeStub* SharedRuntime::_wrong_method_abstract_blob;
78 RuntimeStub* SharedRuntime::_ic_miss_blob;
1917 src->klass()->copy_array((arrayOopDesc*)src, src_pos,
1918 (arrayOopDesc*)dest, dest_pos,
1919 length, thread);
1920 }
1921 JRT_END
1922
1923 // The caller of generate_class_cast_message() (or one of its callers)
1924 // must use a ResourceMark in order to correctly free the result.
1925 char* SharedRuntime::generate_class_cast_message(
1926 JavaThread* thread, Klass* caster_klass) {
1927
1928 // Get target class name from the checkcast instruction
1929 vframeStream vfst(thread, true);
1930 assert(!vfst.at_end(), "Java frame must exist");
1931 Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
1932 Klass* target_klass = vfst.method()->constants()->klass_at(
1933 cc.index(), thread);
1934 return generate_class_cast_message(caster_klass, target_klass);
1935 }
1936
1937 // The caller of class_loader_and_module_name() (or one of its callers)
1938 // must use a ResourceMark in order to correctly free the result.
1939 const char* class_loader_and_module_name(Klass* klass) {
1940 const char* delim = "/";
1941 int delim_len = strlen(delim);
1942
1943 const char* fqn = klass->external_name();
1944 // Length of message to return; always include FQN
1945 size_t msglen = strlen(fqn) + 1;
1946
1947 bool has_cl_name = false;
1948 bool has_mod_name = false;
1949 bool has_version = false;
1950
1951 // Use class loader name, if exists and not builtin
1952 const char* class_loader_name = "";
1953 ClassLoaderData* cld = klass->class_loader_data();
1954 if (cld == NULL || !cld->is_builtin_class_loader_data()) {
1955 // If not builtin, look for internal name
1956 oop loader = klass->class_loader();
1957 if (loader != NULL) {
1958 oopDesc* class_loader = java_lang_ClassLoader::name(loader);
1959 if (class_loader != NULL && class_loader->klass() != NULL) {
1960 class_loader_name = class_loader->klass()->internal_name();
1961 if (class_loader_name != NULL && class_loader_name[0] != '\0') {
1962 has_cl_name = true;
1963 msglen += strlen(class_loader_name) + delim_len;
1964 }
1965 }
1966 }
1967 }
1968
1969 const char* module_name = "";
1970 const char* version = "";
1971 Klass* bottom_klass = klass->is_objArray_klass() ?
1972 ObjArrayKlass::cast(klass)->bottom_klass() : klass;
1973 if (bottom_klass->is_instance_klass()) {
1974 ModuleEntry* module = InstanceKlass::cast(bottom_klass)->module();
1975 // Use module name, if exists
1976 if (module->is_named()) {
1977 has_mod_name = true;
1978 module_name = module->name()->as_C_string();
1979 msglen += strlen(module_name);
1980 // Use version if exists and is not a jdk module
1981 if (module->is_non_jdk_module() && module->version() != NULL) {
1982 has_version = true;
1983 version = module->version()->as_C_string();
1984 msglen += strlen("@") + strlen(version);
1985 }
1986 }
1987 } else {
1988 // klass is an array of primitives, so its module is java.base
1989 module_name = "java.base";
1990 }
1991
1992 if (has_cl_name || has_mod_name) {
1993 msglen += delim_len;
1994 }
1995
1996 char* message = NEW_RESOURCE_ARRAY(char, msglen);
1997
1998 // Just return the FQN if error in allocating string
1999 if (message == NULL) {
2000 return fqn;
2001 }
2002
2003 jio_snprintf(message, msglen, "%s%s%s%s%s%s%s",
2004 class_loader_name,
2005 (has_cl_name) ? delim : "",
2006 (has_mod_name) ? module_name : "",
2007 (has_version) ? "@" : "",
2008 (has_version) ? version : "",
2009 (has_cl_name || has_mod_name) ? delim : "",
2010 fqn);
2011 return message;
2012 }
2013
2014 char* SharedRuntime::generate_class_cast_message(
2015 Klass* caster_klass, Klass* target_klass) {
2016
2017 const char* caster_name = class_loader_and_module_name(caster_klass);
2018
2019 const char* target_name = class_loader_and_module_name(target_klass);
2020
2021 size_t msglen = strlen(caster_name) + strlen(" cannot be cast to ") + strlen(target_name) + 1;
2022
2023 char* message = NEW_RESOURCE_ARRAY(char, msglen);
2024 if (NULL == message) {
2025 // Shouldn't happen, but don't cause even more problems if it does
2026 message = const_cast<char*>(caster_klass->external_name());
2027 } else {
2028 jio_snprintf(message,
2029 msglen,
2030 "%s cannot be cast to %s",
2031 caster_name,
2032 target_name);
2033 }
2034 return message;
2035 }
2036
2037 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
2038 (void) JavaThread::current()->reguard_stack();
2039 JRT_END
2040
2041
2042 // Handles the uncommon case in locking, i.e., contention or an inflated lock.
2043 JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* _obj, BasicLock* lock, JavaThread* thread))
2044 // Disable ObjectSynchronizer::quick_enter() in default config
2045 // on AARCH64 and ARM until JDK-8153107 is resolved.
2046 if (ARM_ONLY((SyncFlags & 256) != 0 &&)
2047 AARCH64_ONLY((SyncFlags & 256) != 0 &&)
2048 !SafepointSynchronize::is_synchronizing()) {
2049 // Only try quick_enter() if we're not trying to reach a safepoint
2050 // so that the calling thread reaches the safepoint more quickly.
2051 if (ObjectSynchronizer::quick_enter(_obj, thread, lock)) return;
2052 }
|