rev 50073 : [mq]: cont

   1 /*
   2  * Copyright (c) 2015, 2018, 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/access.inline.hpp"
  30 #include "oops/oop.inline.hpp"
  31 #include "oops/oopsHierarchy.hpp"
  32 #include "oops/typeArrayOop.inline.hpp"
  33 
  34 void java_lang_String::set_coder(oop string, jbyte coder) {
  35   assert(initialized && (coder_offset > 0), "Must be initialized");
  36   string->byte_field_put(coder_offset, coder);
  37 }
  38 
  39 void java_lang_String::set_value_raw(oop string, typeArrayOop buffer) {
  40   assert(initialized, "Must be initialized");
  41   string->obj_field_put_raw(value_offset, buffer);
  42 }
  43 void java_lang_String::set_value(oop string, typeArrayOop buffer) {
  44   assert(initialized && (value_offset > 0), "Must be initialized");
  45   string->obj_field_put(value_offset, (oop)buffer);
  46 }
  47 void java_lang_String::set_hash(oop string, unsigned int hash) {
  48   assert(initialized && (hash_offset > 0), "Must be initialized");
  49   string->int_field_put(hash_offset, hash);
  50 }
  51 
  52 // Accessors
  53 typeArrayOop java_lang_String::value(oop java_string) {
  54   assert(initialized && (value_offset > 0), "Must be initialized");
  55   assert(is_instance(java_string), "must be java_string");
  56   return (typeArrayOop) java_string->obj_field(value_offset);
  57 }
  58 typeArrayOop java_lang_String::value_no_keepalive(oop java_string) {
  59   assert(initialized && (value_offset > 0), "Must be initialized");
  60   assert(is_instance(java_string), "must be java_string");
  61   return (typeArrayOop) java_string->obj_field_access<AS_NO_KEEPALIVE>(value_offset);
  62 }
  63 unsigned int java_lang_String::hash(oop java_string) {
  64   assert(initialized && (hash_offset > 0), "Must be initialized");
  65   assert(is_instance(java_string), "must be java_string");
  66   return java_string->int_field(hash_offset);
  67 }
  68 bool java_lang_String::is_latin1(oop java_string) {
  69   assert(initialized && (coder_offset > 0), "Must be initialized");
  70   assert(is_instance(java_string), "must be java_string");
  71   jbyte coder = java_string->byte_field(coder_offset);
  72   assert(CompactStrings || coder == CODER_UTF16, "Must be UTF16 without CompactStrings");
  73   return coder == CODER_LATIN1;
  74 }
  75 int java_lang_String::length(oop java_string) {
  76   assert(initialized, "Must be initialized");
  77   assert(is_instance(java_string), "must be java_string");
  78   typeArrayOop value = java_lang_String::value_no_keepalive(java_string);
  79   if (value == NULL) {
  80     return 0;
  81   }
  82   int arr_length = value->length();
  83   if (!is_latin1(java_string)) {
  84     assert((arr_length & 1) == 0, "should be even for UTF16 string");
  85     arr_length >>= 1; // convert number of bytes to number of elements
  86   }
  87   return arr_length;
  88 }
  89 
  90 bool java_lang_String::is_instance_inlined(oop obj) {
  91   return obj != NULL && obj->klass() == SystemDictionary::String_klass();
  92 }
  93 
  94 // Accessors
  95 oop java_lang_ref_Reference::referent(oop ref) {
  96   return ref->obj_field(referent_offset);
  97 }
  98 void java_lang_ref_Reference::set_referent(oop ref, oop value) {
  99   ref->obj_field_put(referent_offset, value);
 100 }
 101 void java_lang_ref_Reference::set_referent_raw(oop ref, oop value) {
 102   ref->obj_field_put_raw(referent_offset, value);
 103 }
 104 HeapWord* java_lang_ref_Reference::referent_addr_raw(oop ref) {
 105   return ref->obj_field_addr_raw<HeapWord>(referent_offset);
 106 }
 107 oop java_lang_ref_Reference::next(oop ref) {
 108   return ref->obj_field(next_offset);
 109 }
 110 void java_lang_ref_Reference::set_next(oop ref, oop value) {
 111   ref->obj_field_put(next_offset, value);
 112 }
 113 void java_lang_ref_Reference::set_next_raw(oop ref, oop value) {
 114   ref->obj_field_put_raw(next_offset, value);
 115 }
 116 HeapWord* java_lang_ref_Reference::next_addr_raw(oop ref) {
 117   return ref->obj_field_addr_raw<HeapWord>(next_offset);
 118 }
 119 oop java_lang_ref_Reference::discovered(oop ref) {
 120   return ref->obj_field(discovered_offset);
 121 }
 122 void java_lang_ref_Reference::set_discovered(oop ref, oop value) {
 123   ref->obj_field_put(discovered_offset, value);
 124 }
 125 void java_lang_ref_Reference::set_discovered_raw(oop ref, oop value) {
 126   ref->obj_field_put_raw(discovered_offset, value);
 127 }
 128 HeapWord* java_lang_ref_Reference::discovered_addr_raw(oop ref) {
 129   return ref->obj_field_addr_raw<HeapWord>(discovered_offset);
 130 }
 131 bool java_lang_ref_Reference::is_phantom(oop ref) {
 132   return InstanceKlass::cast(ref->klass())->reference_type() == REF_PHANTOM;
 133 }
 134 
 135 inline oop java_lang_Continuation::scope(oop ref) {
 136   return ref->obj_field(scope_offset);
 137 }
 138 inline oop java_lang_Continuation::target(oop ref) {
 139   return ref->obj_field(target_offset);
 140 }
 141 inline oop java_lang_Continuation::parent(oop ref) {
 142   return ref->obj_field(parent_offset);
 143 }
 144 inline typeArrayOop java_lang_Continuation::stack(oop ref) {
 145   oop a = ref->obj_field(stack_offset);
 146   return (typeArrayOop)a;
 147 }
 148 inline objArrayOop java_lang_Continuation::refStack(oop ref) {
 149   oop a = ref->obj_field(refStack_offset);
 150   return (objArrayOop)a;
 151 }
 152 inline jlong java_lang_Continuation::fp(oop ref) {
 153   return ref->long_field(fp_offset);
 154 }
 155 inline void java_lang_Continuation::set_fp(oop ref, const jlong i) {
 156   ref->long_field_put(fp_offset, i);
 157 }
 158 inline jint java_lang_Continuation::sp(oop ref) {
 159   return ref->int_field(sp_offset);
 160 }
 161 inline void java_lang_Continuation::set_sp(oop ref, const jint i) {
 162   ref->int_field_put(sp_offset, i);
 163 }
 164 inline void* java_lang_Continuation::pc(oop ref) {
 165   return (void*)ref->long_field(pc_offset);
 166 }
 167 inline void java_lang_Continuation::set_pc(oop ref, const void* pc) {
 168   ref->long_field_put(pc_offset, (long)pc);
 169 }
 170 inline jint java_lang_Continuation::refSP(oop ref) {
 171   return ref->int_field(refSP_offset);
 172 }
 173 inline void java_lang_Continuation::set_refSP(oop ref, jint i) {
 174   ref->int_field_put(refSP_offset, i);
 175 }
 176 inline intptr_t* java_lang_Continuation::entrySP(oop ref) {
 177   return (intptr_t*)ref->long_field(entrySP_offset);
 178 }
 179 inline intptr_t* java_lang_Continuation::entryFP(oop ref) {
 180   return (intptr_t*)ref->long_field(entryFP_offset);
 181 }
 182 inline void java_lang_Continuation::set_entryFP(oop ref, intptr_t* fp) {
 183   ref->long_field_put(entryFP_offset, (long)fp);
 184 }
 185 inline address java_lang_Continuation::entryPC(oop ref) {
 186   return (address)ref->long_field(entryPC_offset);
 187 }
 188 inline void java_lang_Continuation::set_entryPC(oop ref, address pc) {
 189   ref->long_field_put(entryPC_offset, (long)pc);
 190 }
 191 inline int java_lang_Continuation::stack_size(oop ref) {
 192   return stack(ref)->length() * 4;
 193 }
 194 inline void* java_lang_Continuation::stack_base(oop ref) {
 195   return stack(ref)->base(T_INT);
 196 }
 197 inline HeapWord* java_lang_Continuation::refStack_base(oop ref) {
 198   return refStack(ref)->base();
 199 }
 200 
 201 inline void java_lang_invoke_CallSite::set_target_volatile(oop site, oop target) {
 202   site->obj_field_put_volatile(_target_offset, target);
 203 }
 204 
 205 inline oop  java_lang_invoke_CallSite::target(oop site) {
 206   return site->obj_field(_target_offset);
 207 }
 208 
 209 inline void java_lang_invoke_CallSite::set_target(oop site, oop target) {
 210   site->obj_field_put(_target_offset, target);
 211 }
 212 
 213 inline bool java_lang_invoke_CallSite::is_instance(oop obj) {
 214   return obj != NULL && is_subclass(obj->klass());
 215 }
 216 
 217 inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) {
 218   return obj != NULL && is_subclass(obj->klass());
 219 }
 220 
 221 inline bool java_lang_invoke_MemberName::is_instance(oop obj) {
 222   return obj != NULL && obj->klass() == SystemDictionary::MemberName_klass();
 223 }
 224 
 225 inline bool java_lang_invoke_ResolvedMethodName::is_instance(oop obj) {
 226   return obj != NULL && obj->klass() == SystemDictionary::ResolvedMethodName_klass();
 227 }
 228 
 229 inline bool java_lang_invoke_MethodType::is_instance(oop obj) {
 230   return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
 231 }
 232 
 233 inline bool java_lang_invoke_MethodHandle::is_instance(oop obj) {
 234   return obj != NULL && is_subclass(obj->klass());
 235 }
 236 
 237 inline bool java_lang_Class::is_instance(oop obj) {
 238   return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
 239 }
 240 
 241 inline bool java_lang_invoke_DirectMethodHandle::is_instance(oop obj) {
 242   return obj != NULL && is_subclass(obj->klass());
 243 }
 244 
 245 inline bool java_lang_Module::is_instance(oop obj) {
 246   return obj != NULL && obj->klass() == SystemDictionary::Module_klass();
 247 }
 248 
 249 inline int Backtrace::merge_bci_and_version(int bci, int version) {
 250   // only store u2 for version, checking for overflow.
 251   if (version > USHRT_MAX || version < 0) version = USHRT_MAX;
 252   assert((jushort)bci == bci, "bci should be short");
 253   return build_int_from_shorts(version, bci);
 254 }
 255 
 256 inline int Backtrace::merge_mid_and_cpref(int mid, int cpref) {
 257   // only store u2 for mid and cpref, checking for overflow.
 258   assert((jushort)mid == mid, "mid should be short");
 259   assert((jushort)cpref == cpref, "cpref should be short");
 260   return build_int_from_shorts(cpref, mid);
 261 }
 262 
 263 inline int Backtrace::bci_at(unsigned int merged) {
 264   return extract_high_short_from_int(merged);
 265 }
 266 
 267 inline int Backtrace::version_at(unsigned int merged) {
 268   return extract_low_short_from_int(merged);
 269 }
 270 
 271 inline int Backtrace::mid_at(unsigned int merged) {
 272   return extract_high_short_from_int(merged);
 273 }
 274 
 275 inline int Backtrace::cpref_at(unsigned int merged) {
 276   return extract_low_short_from_int(merged);
 277 }
 278 
 279 inline int Backtrace::get_line_number(const methodHandle& method, int bci) {
 280   int line_number = 0;
 281   if (method->is_native()) {
 282     // Negative value different from -1 below, enabling Java code in
 283     // class java.lang.StackTraceElement to distinguish "native" from
 284     // "no LineNumberTable".  JDK tests for -2.
 285     line_number = -2;
 286   } else {
 287     // Returns -1 if no LineNumberTable, and otherwise actual line number
 288     line_number = method->line_number_from_bci(bci);
 289     if (line_number == -1 && ShowHiddenFrames) {
 290       line_number = bci + 1000000;
 291     }
 292   }
 293   return line_number;
 294 }
 295 
 296 inline Symbol* Backtrace::get_source_file_name(InstanceKlass* holder, int version) {
 297   // RedefineClasses() currently permits redefine operations to
 298   // happen in parallel using a "last one wins" philosophy. That
 299   // spec laxness allows the constant pool entry associated with
 300   // the source_file_name_index for any older constant pool version
 301   // to be unstable so we shouldn't try to use it.
 302   if (holder->constants()->version() != version) {
 303     return NULL;
 304   } else {
 305     return holder->source_file_name();
 306   }
 307 }
 308 
 309 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP
--- EOF ---