1 /* 2 * Copyright (c) 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_OOPS_VALUEKLASS_HPP 26 #define SHARE_VM_OOPS_VALUEKLASS_HPP 27 28 #include "oops/instanceKlass.hpp" 29 #include "oops/method.hpp" 30 #include "oops/oop.inline.hpp" 31 32 // A ValueKlass is a specialized InstanceKlass for value types. 33 34 35 class ValueKlass: public InstanceKlass { 36 friend class VMStructs; 37 friend class InstanceKlass; 38 39 private: 40 41 // Constructor 42 ValueKlass(const ClassFileParser& parser) 43 : InstanceKlass(parser, InstanceKlass::_misc_kind_value_type) { } 44 45 // static Klass* array_klass_impl(InstanceKlass* this_k, bool or_null, int n, TRAPS); 46 protected: 47 // Returns the array class for the n'th dimension 48 Klass* array_klass_impl(bool or_null, int n, TRAPS); 49 50 // Returns the array class with this class as element type 51 Klass* array_klass_impl(bool or_null, TRAPS); 52 53 public: 54 // Type testing 55 bool is_value_slow() const { return true; } 56 57 // Casting from Klass* 58 static ValueKlass* cast(Klass* k) { 59 assert(k->is_value(), "cast to ValueKlass"); 60 return (ValueKlass*) k; 61 } 62 63 // Use this to return the size of an instance in heap words 64 // Implementation is currently simple because all value types are allocated 65 // in Java heap like Java objects. 66 virtual int size_helper() const { 67 return layout_helper_to_size_helper(layout_helper()); 68 } 69 70 // minimum number of bytes occupied by nonstatic fields, HeapWord aligned or pow2 71 int raw_value_byte_size() const; 72 73 int first_field_offset() const; 74 75 address data_for_oop(oop o) const { 76 return ((address) (void*) o) + first_field_offset(); 77 } 78 79 oop oop_for_data(address data) const { 80 oop o = (oop) (data - first_field_offset()); 81 assert(o->is_oop(false), "Not an oop"); 82 return o; 83 } 84 85 // Query if h/w provides atomic load/store 86 bool is_atomic(); 87 88 bool flatten_array(); 89 90 bool contains_oops() const { return nonstatic_oop_map_count() > 0; } 91 int nonstatic_oop_count(); 92 93 // Prototype general store methods... 94 95 // copy the fields, with no concern for GC barriers 96 void raw_field_copy(void* src, void* dst, size_t raw_byte_size); 97 98 void value_store(void* src, void* dst, bool dst_is_heap, bool dst_uninitialized) { 99 value_store(src, dst, nonstatic_field_size() << LogBytesPerHeapOop, dst_is_heap, dst_uninitialized); 100 } 101 102 // store the value of this klass contained with src into dst, raw data ptr 103 void value_store(void* src, void* dst, size_t raw_byte_size, bool dst_is_heap, bool dst_uninitialized); 104 105 106 oop derive_value_type_copy(Handle src, InstanceKlass* target_klass, TRAPS); 107 108 // GC support... 109 110 // oop iterate raw value type data pointer (where oop_addr may not be an oop, but backing/array-element) 111 template <bool nv, typename T, class OopClosureType> 112 inline void oop_iterate_specialized(const address oop_addr, OopClosureType* closure); 113 114 template <bool nv, typename T, class OopClosureType> 115 inline void oop_iterate_specialized_bounded(const address oop_addr, OopClosureType* closure, void* lo, void* hi); 116 117 }; 118 119 #endif /* SHARE_VM_OOPS_VALUEKLASS_HPP */