1 /* 2 * Copyright (c) 2015, 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_VM_CLASSFILE_JAVACLASSES_INLINE_HPP 26 #define SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP 27 28 #include "classfile/javaClasses.hpp" 29 #include "oops/oop.inline.hpp" 30 #include "oops/oopsHierarchy.hpp" 31 32 inline void java_lang_invoke_CallSite::set_target_volatile(oop site, oop target) { 33 site->obj_field_put_volatile(_target_offset, target); 34 } 35 36 inline oop java_lang_invoke_CallSite::target(oop site) { 37 return site->obj_field(_target_offset); 38 } 39 40 inline void java_lang_invoke_CallSite::set_target(oop site, oop target) { 41 site->obj_field_put(_target_offset, target); 42 } 43 44 inline bool java_lang_String::is_instance_inlined(oop obj) { 45 return obj != NULL && obj->klass() == SystemDictionary::String_klass(); 46 } 47 48 inline bool java_lang_invoke_CallSite::is_instance(oop obj) { 49 return obj != NULL && is_subclass(obj->klass()); 50 } 51 52 inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) { 53 return obj != NULL && is_subclass(obj->klass()); 54 } 55 56 inline bool java_lang_invoke_MemberName::is_instance(oop obj) { 57 return obj != NULL && is_subclass(obj->klass()); 58 } 59 60 inline bool java_lang_invoke_MethodType::is_instance(oop obj) { 61 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass(); 62 } 63 64 inline bool java_lang_invoke_MethodHandle::is_instance(oop obj) { 65 return obj != NULL && is_subclass(obj->klass()); 66 } 67 68 inline bool java_lang_Class::is_instance(oop obj) { 69 return obj != NULL && obj->klass() == SystemDictionary::Class_klass(); 70 } 71 72 inline bool java_lang_invoke_DirectMethodHandle::is_instance(oop obj) { 73 return obj != NULL && is_subclass(obj->klass()); 74 } 75 76 inline int Backtrace::merge_bci_and_version(int bci, int version) { 77 // only store u2 for version, checking for overflow. 78 if (version > USHRT_MAX || version < 0) version = USHRT_MAX; 79 assert((jushort)bci == bci, "bci should be short"); 80 return build_int_from_shorts(version, bci); 81 } 82 83 inline int Backtrace::merge_mid_and_cpref(int mid, int cpref) { 84 // only store u2 for mid and cpref, checking for overflow. 85 assert((jushort)mid == mid, "mid should be short"); 86 assert((jushort)cpref == cpref, "cpref should be short"); 87 return build_int_from_shorts(cpref, mid); 88 } 89 90 inline int Backtrace::bci_at(unsigned int merged) { 91 return extract_high_short_from_int(merged); 92 } 93 94 inline int Backtrace::version_at(unsigned int merged) { 95 return extract_low_short_from_int(merged); 96 } 97 98 inline int Backtrace::mid_at(unsigned int merged) { 99 return extract_high_short_from_int(merged); 100 } 101 102 inline int Backtrace::cpref_at(unsigned int merged) { 103 return extract_low_short_from_int(merged); 104 } 105 106 inline int Backtrace::get_line_number(const methodHandle& method, int bci) { 107 int line_number = 0; 108 if (method->is_native()) { 109 // Negative value different from -1 below, enabling Java code in 110 // class java.lang.StackTraceElement to distinguish "native" from 111 // "no LineNumberTable". JDK tests for -2. 112 line_number = -2; 113 } else { 114 // Returns -1 if no LineNumberTable, and otherwise actual line number 115 line_number = method->line_number_from_bci(bci); 116 if (line_number == -1 && ShowHiddenFrames) { 117 line_number = bci + 1000000; 118 } 119 } 120 return line_number; 121 } 122 123 /* 124 * Returns the source file name of a given InstanceKlass and version 125 */ 126 inline Symbol* Backtrace::get_source_file_name(InstanceKlass* holder, int version) { 127 // Find the specific ik version that contains this source_file_name_index 128 // via the previous versions list, but use the current version's 129 // constant pool to look it up. The previous version's index has been 130 // merged for the current constant pool. 131 InstanceKlass* ik = holder->get_klass_version(version); 132 // This version has been cleaned up. 133 if (ik == NULL) return NULL; 134 int source_file_name_index = ik->source_file_name_index(); 135 return (source_file_name_index == 0) ? 136 (Symbol*)NULL : holder->constants()->symbol_at(source_file_name_index); 137 } 138 139 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP