1 /* 2 * Copyright (c) 2015, 2017, 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 void java_lang_String::set_coder(oop string, jbyte coder) { 33 assert(initialized && (coder_offset > 0), "Must be initialized"); 34 string->byte_field_put(coder_offset, coder); 35 } 36 37 void java_lang_String::set_value_raw(oop string, typeArrayOop buffer) { 38 assert(initialized, "Must be initialized"); 39 string->obj_field_put_raw(value_offset, buffer); 40 } 41 void java_lang_String::set_value(oop string, typeArrayOop buffer) { 42 assert(initialized && (value_offset > 0), "Must be initialized"); 43 string->obj_field_put(value_offset, (oop)buffer); 44 } 45 void java_lang_String::set_hash(oop string, unsigned int hash) { 46 assert(initialized && (hash_offset > 0), "Must be initialized"); 47 string->int_field_put(hash_offset, hash); 48 } 49 50 // Accessors 51 typeArrayOop java_lang_String::value(oop java_string) { 52 assert(initialized && (value_offset > 0), "Must be initialized"); 53 assert(is_instance(java_string), "must be java_string"); 54 return (typeArrayOop) java_string->obj_field(value_offset); 55 } 56 unsigned int java_lang_String::hash(oop java_string) { 57 assert(initialized && (hash_offset > 0), "Must be initialized"); 58 assert(is_instance(java_string), "must be java_string"); 59 return java_string->int_field(hash_offset); 60 } 61 bool java_lang_String::is_latin1(oop java_string) { 62 assert(initialized && (coder_offset > 0), "Must be initialized"); 63 assert(is_instance(java_string), "must be java_string"); 64 jbyte coder = java_string->byte_field(coder_offset); 65 assert(CompactStrings || coder == CODER_UTF16, "Must be UTF16 without CompactStrings"); 66 return coder == CODER_LATIN1; 67 } 68 int java_lang_String::length(oop java_string) { 69 assert(initialized, "Must be initialized"); 70 assert(is_instance(java_string), "must be java_string"); 71 typeArrayOop value_array = ((typeArrayOop)java_string->obj_field(value_offset)); 72 if (value_array == NULL) { 73 return 0; 74 } 75 int arr_length = value_array->length(); 76 if (!is_latin1(java_string)) { 77 assert((arr_length & 1) == 0, "should be even for UTF16 string"); 78 arr_length >>= 1; // convert number of bytes to number of elements 79 } 80 return arr_length; 81 } 82 83 bool java_lang_String::is_instance_inlined(oop obj) { 84 return obj != NULL && obj->klass() == SystemDictionary::String_klass(); 85 } 86 87 // Accessors 88 oop java_lang_ref_Reference::referent(oop ref) { 89 return ref->obj_field(referent_offset); 90 } 91 void java_lang_ref_Reference::set_referent(oop ref, oop value) { 92 ref->obj_field_put(referent_offset, value); 93 } 94 void java_lang_ref_Reference::set_referent_raw(oop ref, oop value) { 95 ref->obj_field_put_raw(referent_offset, value); 96 } 97 HeapWord* java_lang_ref_Reference::referent_addr(oop ref) { 98 return ref->obj_field_addr<HeapWord>(referent_offset); 99 } 100 oop java_lang_ref_Reference::next(oop ref) { 101 return ref->obj_field(next_offset); 102 } 103 void java_lang_ref_Reference::set_next(oop ref, oop value) { 104 ref->obj_field_put(next_offset, value); 105 } 106 void java_lang_ref_Reference::set_next_raw(oop ref, oop value) { 107 ref->obj_field_put_raw(next_offset, value); 108 } 109 HeapWord* java_lang_ref_Reference::next_addr(oop ref) { 110 return ref->obj_field_addr<HeapWord>(next_offset); 111 } 112 oop java_lang_ref_Reference::discovered(oop ref) { 113 return ref->obj_field(discovered_offset); 114 } 115 void java_lang_ref_Reference::set_discovered(oop ref, oop value) { 116 ref->obj_field_put(discovered_offset, value); 117 } 118 void java_lang_ref_Reference::set_discovered_raw(oop ref, oop value) { 119 ref->obj_field_put_raw(discovered_offset, value); 120 } 121 HeapWord* java_lang_ref_Reference::discovered_addr(oop ref) { 122 return ref->obj_field_addr<HeapWord>(discovered_offset); 123 } 124 bool java_lang_ref_Reference::is_phantom(oop ref) { 125 return InstanceKlass::cast(ref->klass())->reference_type() == REF_PHANTOM; 126 } 127 128 inline void java_lang_invoke_CallSite::set_target_volatile(oop site, oop target) { 129 site->obj_field_put_volatile(_target_offset, target); 130 } 131 132 inline oop java_lang_invoke_CallSite::target(oop site) { 133 return site->obj_field(_target_offset); 134 } 135 136 inline void java_lang_invoke_CallSite::set_target(oop site, oop target) { 137 site->obj_field_put(_target_offset, target); 138 } 139 140 inline bool java_lang_invoke_CallSite::is_instance(oop obj) { 141 return obj != NULL && is_subclass(obj->klass()); 142 } 143 144 inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) { 145 return obj != NULL && is_subclass(obj->klass()); 146 } 147 148 inline bool java_lang_invoke_MemberName::is_instance(oop obj) { 149 return obj != NULL && obj->klass() == SystemDictionary::MemberName_klass(); 150 } 151 152 inline bool java_lang_invoke_ResolvedMethodName::is_instance(oop obj) { 153 return obj != NULL && obj->klass() == SystemDictionary::ResolvedMethodName_klass(); 154 } 155 156 inline bool java_lang_invoke_MethodType::is_instance(oop obj) { 157 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass(); 158 } 159 160 inline bool java_lang_invoke_MethodHandle::is_instance(oop obj) { 161 return obj != NULL && is_subclass(obj->klass()); 162 } 163 164 inline bool java_lang_Class::is_instance(oop obj) { 165 return obj != NULL && obj->klass() == SystemDictionary::Class_klass(); 166 } 167 168 inline bool java_lang_invoke_DirectMethodHandle::is_instance(oop obj) { 169 return obj != NULL && is_subclass(obj->klass()); 170 } 171 172 inline bool java_lang_Module::is_instance(oop obj) { 173 return obj != NULL && obj->klass() == SystemDictionary::Module_klass(); 174 } 175 176 inline int Backtrace::merge_bci_and_version(int bci, int version) { 177 // only store u2 for version, checking for overflow. 178 if (version > USHRT_MAX || version < 0) version = USHRT_MAX; 179 assert((jushort)bci == bci, "bci should be short"); 180 return build_int_from_shorts(version, bci); 181 } 182 183 inline int Backtrace::merge_mid_and_cpref(int mid, int cpref) { 184 // only store u2 for mid and cpref, checking for overflow. 185 assert((jushort)mid == mid, "mid should be short"); 186 assert((jushort)cpref == cpref, "cpref should be short"); 187 return build_int_from_shorts(cpref, mid); 188 } 189 190 inline int Backtrace::bci_at(unsigned int merged) { 191 return extract_high_short_from_int(merged); 192 } 193 194 inline int Backtrace::version_at(unsigned int merged) { 195 return extract_low_short_from_int(merged); 196 } 197 198 inline int Backtrace::mid_at(unsigned int merged) { 199 return extract_high_short_from_int(merged); 200 } 201 202 inline int Backtrace::cpref_at(unsigned int merged) { 203 return extract_low_short_from_int(merged); 204 } 205 206 inline int Backtrace::get_line_number(const methodHandle& method, int bci) { 207 int line_number = 0; 208 if (method->is_native()) { 209 // Negative value different from -1 below, enabling Java code in 210 // class java.lang.StackTraceElement to distinguish "native" from 211 // "no LineNumberTable". JDK tests for -2. 212 line_number = -2; 213 } else { 214 // Returns -1 if no LineNumberTable, and otherwise actual line number 215 line_number = method->line_number_from_bci(bci); 216 if (line_number == -1 && ShowHiddenFrames) { 217 line_number = bci + 1000000; 218 } 219 } 220 return line_number; 221 } 222 223 inline Symbol* Backtrace::get_source_file_name(InstanceKlass* holder, int version) { 224 // RedefineClasses() currently permits redefine operations to 225 // happen in parallel using a "last one wins" philosophy. That 226 // spec laxness allows the constant pool entry associated with 227 // the source_file_name_index for any older constant pool version 228 // to be unstable so we shouldn't try to use it. 229 if (holder->constants()->version() != version) { 230 return NULL; 231 } else { 232 return holder->source_file_name(); 233 } 234 } 235 236 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP