--- /dev/null 2019-03-11 09:22:42.048915961 +0100 +++ new/src/hotspot/share/oops/valueKlass.hpp 2019-03-11 14:26:30.906354813 +0100 @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_OOPS_VALUEKLASS_HPP +#define SHARE_VM_OOPS_VALUEKLASS_HPP + +#include "classfile/javaClasses.hpp" +#include "oops/instanceKlass.hpp" +#include "oops/method.hpp" +#include "oops/oop.inline.hpp" + +// A ValueKlass is a specialized InstanceKlass for value types. + + +class ValueKlass: public InstanceKlass { + friend class VMStructs; + friend class InstanceKlass; + + private: + + // Constructor + ValueKlass(const ClassFileParser& parser) + : InstanceKlass(parser, InstanceKlass::_misc_kind_value_type, InstanceKlass::ID) { + _adr_valueklass_fixed_block = valueklass_static_block(); + // Addresses used for value type calling convention + *((Array**)adr_extended_sig()) = NULL; + *((Array**)adr_return_regs()) = NULL; + *((address*)adr_pack_handler()) = NULL; + *((address*)adr_unpack_handler()) = NULL; + assert(pack_handler() == NULL, "pack handler not null"); + *((int*)adr_default_value_offset()) = 0; + set_prototype_header(markOopDesc::always_locked_prototype()); + } + + ValueKlassFixedBlock* valueklass_static_block() const { + address adr_jf = adr_value_fields_klasses(); + if (adr_jf != NULL) { + return (ValueKlassFixedBlock*)(adr_jf + this->java_fields_count() * sizeof(Klass*)); + } + + address adr_fing = adr_fingerprint(); + if (adr_fing != NULL) { + return (ValueKlassFixedBlock*)(adr_fingerprint() + sizeof(u8)); + } + + InstanceKlass** adr_host = adr_unsafe_anonymous_host(); + if (adr_host != NULL) { + return (ValueKlassFixedBlock*)(adr_host + 1); + } + + Klass* volatile* adr_impl = adr_implementor(); + if (adr_impl != NULL) { + return (ValueKlassFixedBlock*)(adr_impl + 1); + } + + return (ValueKlassFixedBlock*)end_of_nonstatic_oop_maps(); + } + + address adr_extended_sig() const { + assert(_adr_valueklass_fixed_block != NULL, "Should have been initialized"); + return ((address)_adr_valueklass_fixed_block) + in_bytes(byte_offset_of(ValueKlassFixedBlock, _extended_sig)); + } + + address adr_return_regs() const { + ValueKlassFixedBlock* vkst = valueklass_static_block(); + return ((address)_adr_valueklass_fixed_block) + in_bytes(byte_offset_of(ValueKlassFixedBlock, _return_regs)); + } + + // pack and unpack handlers for value types return + address adr_pack_handler() const { + assert(_adr_valueklass_fixed_block != NULL, "Should have been initialized"); + return ((address)_adr_valueklass_fixed_block) + in_bytes(byte_offset_of(ValueKlassFixedBlock, _pack_handler)); + } + + address adr_unpack_handler() const { + assert(_adr_valueklass_fixed_block != NULL, "Should have been initialized"); + return ((address)_adr_valueklass_fixed_block) + in_bytes(byte_offset_of(ValueKlassFixedBlock, _unpack_handler)); + } + + address pack_handler() const { + return *(address*)adr_pack_handler(); + } + + address unpack_handler() const { + return *(address*)adr_unpack_handler(); + } + + address adr_default_value_offset() const { + assert(_adr_valueklass_fixed_block != NULL, "Should have been initialized"); + return ((address)_adr_valueklass_fixed_block) + in_bytes(default_value_offset_offset()); + } + + int collect_fields(GrowableArray* sig, int base_off = 0) const; + + void cleanup_blobs(); + + protected: + // Returns the array class for the n'th dimension + Klass* array_klass_impl(bool or_null, int n, TRAPS); + + // Returns the array class with this class as element type + Klass* array_klass_impl(bool or_null, TRAPS); + + public: + // Type testing + bool is_value_slow() const { return true; } + + oop value_mirror() const { + return java_lang_Class::value_mirror(java_mirror()); + } + + // Casting from Klass* + static ValueKlass* cast(Klass* k) { + assert(k->is_value(), "cast to ValueKlass"); + return (ValueKlass*) k; + } + + // Use this to return the size of an instance in heap words + // Implementation is currently simple because all value types are allocated + // in Java heap like Java objects. + virtual int size_helper() const { + return layout_helper_to_size_helper(layout_helper()); + } + + // allocate_instance() allocates a stand alone value in the Java heap + instanceOop allocate_instance(TRAPS); + + // minimum number of bytes occupied by nonstatic fields, HeapWord aligned or pow2 + int raw_value_byte_size() const; + + int first_field_offset() const; + + address data_for_oop(oop o) const { + return ((address) (void*) o) + first_field_offset(); + } + + oop oop_for_data(address data) const { + oop o = (oop) (data - first_field_offset()); + assert(oopDesc::is_oop(o, false), "Not an oop"); + return o; + } + + // Query if h/w provides atomic load/store + bool is_atomic(); + + bool flatten_array(); + + bool contains_oops() const { return nonstatic_oop_map_count() > 0; } + int nonstatic_oop_count(); + + // Prototype general store methods... + + // copy the fields, with no concern for GC barriers + void raw_field_copy(void* src, void* dst, size_t raw_byte_size); + + void value_store(void* src, void* dst, bool dst_is_heap, bool dst_uninitialized) { + value_store(src, dst, nonstatic_field_size() << LogBytesPerHeapOop, dst_is_heap, dst_uninitialized); + } + + // store the value of this klass contained with src into dst, raw data ptr + void value_store(void* src, void* dst, size_t raw_byte_size, bool dst_is_heap, bool dst_uninitialized); + + // GC support... + + void iterate_over_inside_oops(OopClosure* f, oop value); + + // oop iterate raw value type data pointer (where oop_addr may not be an oop, but backing/array-element) + template + inline void oop_iterate_specialized(const address oop_addr, OopClosureType* closure); + + template + inline void oop_iterate_specialized_bounded(const address oop_addr, OopClosureType* closure, void* lo, void* hi); + + // calling convention support + void initialize_calling_convention(TRAPS); + Array* extended_sig() const { + return *((Array**)adr_extended_sig()); + } + Array* return_regs() const { + return *((Array**)adr_return_regs()); + } + bool can_be_returned_as_fields() const; + void save_oop_fields(const RegisterMap& map, GrowableArray& handles) const; + void restore_oop_results(RegisterMap& map, GrowableArray& handles) const; + oop realloc_result(const RegisterMap& reg_map, const GrowableArray& handles, TRAPS); + static ValueKlass* returned_value_klass(const RegisterMap& reg_map); + + // pack and unpack handlers. Need to be loadable from generated code + // so at a fixed offset from the base of the klass pointer. + static ByteSize pack_handler_offset() { + return byte_offset_of(ValueKlassFixedBlock, _pack_handler); + } + + static ByteSize unpack_handler_offset() { + return byte_offset_of(ValueKlassFixedBlock, _unpack_handler); + } + + static ByteSize default_value_offset_offset() { + return byte_offset_of(ValueKlassFixedBlock, _default_value_offset); + } + + void set_default_value_offset(int offset) { + *((int*)adr_default_value_offset()) = offset; + } + + int default_value_offset() { + int offset = *((int*)adr_default_value_offset()); + assert(offset != 0, "must not be called if not initialized"); + return offset; + } + + void set_default_value(oop val) { + java_mirror()->obj_field_put(default_value_offset(), val); + } + + oop default_value() { + oop val = java_mirror()->obj_field_acquire(default_value_offset()); + assert(oopDesc::is_oop(val), "Sanity check"); + assert(val->is_value(), "Sanity check"); + assert(val->klass() == this, "sanity check"); + return val; + } + + void deallocate_contents(ClassLoaderData* loader_data); + static void cleanup(ValueKlass* ik) ; + + // Verification + void verify_on(outputStream* st); + void oop_verify_on(oop obj, outputStream* st); + +}; + +#endif /* SHARE_VM_OOPS_VALUEKLASS_HPP */