--- old/src/hotspot/share/gc/z/zAddressRangeMap.hpp 2018-01-13 12:11:19.212084218 +0900 +++ new/src/hotspot/share/gc/z/zAddressRangeMap.hpp 2018-01-13 12:11:18.931083458 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, 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 @@ -31,6 +31,7 @@ template class ZAddressRangeMap VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; friend class ZAddressRangeMapIterator; private: --- old/src/hotspot/share/gc/z/zCollectedHeap.hpp 2018-01-13 12:11:20.047086479 +0900 +++ new/src/hotspot/share/gc/z/zCollectedHeap.hpp 2018-01-13 12:11:19.778085751 +0900 @@ -33,6 +33,8 @@ #include "gc/z/zStat.hpp" class ZCollectedHeap : public CollectedHeap { + friend class VMStructs; + private: ZCollectorPolicy* _policy; ZBarrierSet _barrier; --- old/src/hotspot/share/gc/z/zForwardingTable.hpp 2018-01-13 12:11:20.863088689 +0900 +++ new/src/hotspot/share/gc/z/zForwardingTable.hpp 2018-01-13 12:11:20.594087960 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -30,6 +30,7 @@ typedef size_t ZForwardingTableCursor; class ZForwardingTable VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; friend class ZForwardingTableTest; private: --- old/src/hotspot/share/gc/z/zHeap.hpp 2018-01-13 12:11:21.689090925 +0900 +++ new/src/hotspot/share/gc/z/zHeap.hpp 2018-01-13 12:11:21.412090175 +0900 @@ -45,6 +45,8 @@ #include "memory/allocation.hpp" class ZHeap VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; + private: static ZHeap* _heap; --- old/src/hotspot/share/gc/z/zPage.hpp 2018-01-13 12:11:22.504093132 +0900 +++ new/src/hotspot/share/gc/z/zPage.hpp 2018-01-13 12:11:22.234092401 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -32,6 +32,7 @@ #include "memory/allocation.hpp" class ZPage : public CHeapObj { + friend class VMStructs; friend class ZList; private: --- old/src/hotspot/share/gc/z/zPageAllocator.hpp 2018-01-13 12:11:23.323095349 +0900 +++ new/src/hotspot/share/gc/z/zPageAllocator.hpp 2018-01-13 12:11:23.054094621 +0900 @@ -36,6 +36,8 @@ class ZPageAllocRequest; class ZPageAllocator VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; + private: ZLock _lock; ZVirtualMemoryManager _virtual; --- old/src/hotspot/share/gc/z/zPageTable.hpp 2018-01-13 12:11:24.149097586 +0900 +++ new/src/hotspot/share/gc/z/zPageTable.hpp 2018-01-13 12:11:23.880096857 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -32,6 +32,7 @@ class ZPage; class ZPageTable VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; friend class ZPageTableIterator; private: --- old/src/hotspot/share/gc/z/zPhysicalMemory.hpp 2018-01-13 12:11:24.965099795 +0900 +++ new/src/hotspot/share/gc/z/zPhysicalMemory.hpp 2018-01-13 12:11:24.697099070 +0900 @@ -65,6 +65,8 @@ }; class ZPhysicalMemoryManager VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; + private: ZPhysicalMemoryBacking _backing; const size_t _max_capacity; --- old/src/hotspot/share/gc/z/zVirtualMemory.hpp 2018-01-13 12:11:25.788102024 +0900 +++ new/src/hotspot/share/gc/z/zVirtualMemory.hpp 2018-01-13 12:11:25.512101276 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -28,6 +28,8 @@ #include "memory/allocation.hpp" class ZVirtualMemory VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; + private: uintptr_t _start; uintptr_t _end; --- old/src/hotspot/share/runtime/vmStructs.cpp 2018-01-13 12:11:26.609104246 +0900 +++ new/src/hotspot/share/runtime/vmStructs.cpp 2018-01-13 12:11:26.338103513 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2018, 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 @@ -127,6 +127,7 @@ #include "gc/parallel/psVirtualspace.hpp" #include "gc/parallel/psYoungGen.hpp" #include "gc/parallel/vmStructs_parallelgc.hpp" +#include "gc/z/vmStructs_z.hpp" #endif // INCLUDE_ALL_GCS #if INCLUDE_JVMCI @@ -1390,6 +1391,7 @@ declare_integer_type(intptr_t) \ declare_unsigned_integer_type(uintx) \ declare_unsigned_integer_type(uintptr_t) \ + declare_unsigned_integer_type(uint8_t) \ declare_unsigned_integer_type(uint32_t) \ declare_unsigned_integer_type(uint64_t) \ \ @@ -3023,6 +3025,9 @@ VM_STRUCTS_G1(GENERATE_NONSTATIC_VM_STRUCT_ENTRY, GENERATE_STATIC_VM_STRUCT_ENTRY) + + VM_STRUCTS_Z(GENERATE_NONSTATIC_VM_STRUCT_ENTRY, + GENERATE_STATIC_VM_STRUCT_ENTRY) #endif // INCLUDE_ALL_GCS #if INCLUDE_TRACE @@ -3090,6 +3095,9 @@ VM_TYPES_G1(GENERATE_VM_TYPE_ENTRY, GENERATE_TOPLEVEL_VM_TYPE_ENTRY, GENERATE_INTEGER_VM_TYPE_ENTRY) + + VM_TYPES_Z(GENERATE_VM_TYPE_ENTRY, + GENERATE_TOPLEVEL_VM_TYPE_ENTRY) #endif // INCLUDE_ALL_GCS #if INCLUDE_TRACE @@ -3149,6 +3157,9 @@ VM_INT_CONSTANTS_G1(GENERATE_VM_INT_CONSTANT_ENTRY, GENERATE_VM_INT_CONSTANT_WITH_VALUE_ENTRY) + + VM_INT_CONSTANTS_Z(GENERATE_VM_INT_CONSTANT_ENTRY, + GENERATE_VM_INT_CONSTANT_WITH_VALUE_ENTRY) #endif // INCLUDE_ALL_GCS #if INCLUDE_TRACE @@ -3206,6 +3217,12 @@ GENERATE_C2_VM_LONG_CONSTANT_ENTRY, GENERATE_C2_PREPROCESSOR_VM_LONG_CONSTANT_ENTRY) +#if INCLUDE_ALL_GCS + + VM_LONG_CONSTANTS_Z(GENERATE_VM_INT_CONSTANT_ENTRY, + GENERATE_VM_INT_CONSTANT_WITH_VALUE_ENTRY) +#endif // INCLUDE_ALL_GCS + GENERATE_VM_LONG_CONSTANT_LAST_ENTRY() }; @@ -3240,6 +3257,9 @@ VM_STRUCTS_G1(CHECK_NONSTATIC_VM_STRUCT_ENTRY, CHECK_STATIC_VM_STRUCT_ENTRY); + VM_STRUCTS_Z(CHECK_NONSTATIC_VM_STRUCT_ENTRY, + CHECK_STATIC_VM_STRUCT_ENTRY); + #endif // INCLUDE_ALL_GCS #if INCLUDE_TRACE @@ -3290,6 +3310,8 @@ CHECK_SINGLE_ARG_VM_TYPE_NO_OP, CHECK_SINGLE_ARG_VM_TYPE_NO_OP); + VM_TYPES_Z(CHECK_VM_TYPE_ENTRY, + CHECK_SINGLE_ARG_VM_TYPE_NO_OP); #endif // INCLUDE_ALL_GCS #if INCLUDE_TRACE @@ -3364,6 +3386,8 @@ ENSURE_FIELD_TYPE_PRESENT)); debug_only(VM_STRUCTS_G1(ENSURE_FIELD_TYPE_PRESENT, ENSURE_FIELD_TYPE_PRESENT)); + debug_only(VM_STRUCTS_Z(ENSURE_FIELD_TYPE_PRESENT, + ENSURE_FIELD_TYPE_PRESENT)); #endif // INCLUDE_ALL_GCS #if INCLUDE_TRACE --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeap.java 2018-01-13 12:11:27.662107098 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeap.java 2018-01-13 12:11:27.395106375 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2018, 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 @@ -75,6 +75,16 @@ public abstract CollectedHeapName kind(); + public OopHandle oop_load_at(OopHandle handle, long offset) { + return VM.getVM().isCompressedOopsEnabled() + ? handle.getCompOopHandleAt(offset) + : handle.getOopHandleAt(offset); + } + + public String oopAddressDescription(OopHandle handle) { + return handle.toString(); + } + public void print() { printOn(System.out); } public void printOn(PrintStream tty) { MemRegion mr = reservedRegion(); --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java 2018-01-13 12:11:28.657109792 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java 2018-01-13 12:11:28.382109047 +0900 @@ -36,6 +36,7 @@ public static final CollectedHeapName SERIAL_HEAP = new CollectedHeapName("SerialHeap"); public static final CollectedHeapName G1_COLLECTED_HEAP = new CollectedHeapName("G1CollectedHeap"); public static final CollectedHeapName PARALLEL_SCAVENGE_HEAP = new CollectedHeapName("ParallelScavengeHeap"); + public static final CollectedHeapName Z_COLLECTED_HEAP = new CollectedHeapName("ZCollectedHeap"); public String toString() { return name; --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java 2018-01-13 12:11:29.516112117 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java 2018-01-13 12:11:29.242111376 +0900 @@ -32,6 +32,7 @@ import sun.jvm.hotspot.gc.shared.*; import sun.jvm.hotspot.gc.g1.G1CollectedHeap; import sun.jvm.hotspot.gc.parallel.*; +import sun.jvm.hotspot.gc.z.ZCollectedHeap; import sun.jvm.hotspot.oops.*; import sun.jvm.hotspot.types.*; import sun.jvm.hotspot.runtime.*; @@ -82,6 +83,7 @@ heapConstructor.addMapping("SerialHeap", SerialHeap.class); heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class); heapConstructor.addMapping("G1CollectedHeap", G1CollectedHeap.class); + heapConstructor.addMapping("ZCollectedHeap", ZCollectedHeap.class); mainThreadGroupField = type.getOopField("_main_thread_group"); systemThreadGroupField = type.getOopField("_system_thread_group"); --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Oop.java 2018-01-13 12:11:30.397114503 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Oop.java 2018-01-13 12:11:30.119113750 +0900 @@ -164,7 +164,7 @@ tty.print("null"); } else { obj.printValueOn(tty); - tty.print(" @ " + obj.getHandle()); + tty.print(" @ " + VM.getVM().getUniverse().heap().oopAddressDescription(obj.getHandle())); } } --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/OopField.java 2018-01-13 12:11:31.392117197 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/OopField.java 2018-01-13 12:11:31.122116466 +0900 @@ -54,7 +54,8 @@ if (!isVMField() && !obj.isInstance() && !obj.isArray()) { throw new InternalError(obj.toString()); } - return obj.getHandle().getOopHandleAt(getOffset()); + + return VM.getVM().getUniverse().heap().oop_load_at(obj.getHandle(), getOffset()); } public Oop getValue(VMObject obj) { --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/hotspot/share/gc/z/vmStructs_z.hpp 2018-01-13 12:11:32.105119127 +0900 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017, 2018, 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_GC_Z_VMSTRUCTS_Z_HPP +#define SHARE_VM_GC_Z_VMSTRUCTS_Z_HPP + +#include "gc/z/zCollectedHeap.hpp" +#include "gc/z/zHeap.hpp" +#include "gc/z/zPageAllocator.hpp" +#include "gc/z/zPhysicalMemory.hpp" +#include "gc/z/zAddressRangeMap.hpp" +#include "utilities/macros.hpp" + +typedef ZAddressRangeMap ZAddressRangeMapForPageTable; + +#define VM_STRUCTS_Z(nonstatic_field, static_field) \ + nonstatic_field(ZCollectedHeap, _heap, ZHeap) \ + \ + nonstatic_field(ZHeap, _page_allocator, ZPageAllocator) \ + nonstatic_field(ZHeap, _pagetable, ZPageTable) \ + \ + nonstatic_field(ZPage, _type, const uint8_t) \ + nonstatic_field(ZPage, _virtual, const ZVirtualMemory) \ + nonstatic_field(ZPage, _forwarding, ZForwardingTable) \ + \ + nonstatic_field(ZPageAllocator, _physical, ZPhysicalMemoryManager) \ + nonstatic_field(ZPageAllocator, _used, size_t) \ + \ + nonstatic_field(ZPageTable, _map, ZAddressRangeMapForPageTable) \ + \ + nonstatic_field(ZAddressRangeMapForPageTable, _map, ZPageTableEntry* const) \ + \ + nonstatic_field(ZVirtualMemory, _start, uintptr_t) \ + nonstatic_field(ZVirtualMemory, _end, uintptr_t) \ + \ + nonstatic_field(ZForwardingTable, _table, ZForwardingTableEntry*) \ + nonstatic_field(ZForwardingTable, _size, size_t) \ + \ + nonstatic_field(ZPhysicalMemoryManager, _max_capacity, const size_t) \ + nonstatic_field(ZPhysicalMemoryManager, _capacity, size_t) + +#define VM_INT_CONSTANTS_Z(declare_constant, declare_constant_with_value) \ + declare_constant(ZGlobalPhase) \ + declare_constant(ZPhaseRelocate) \ + declare_constant(ZPageTypeSmall) \ + declare_constant(ZPageTypeMedium) \ + declare_constant(ZPageTypeLarge) \ + declare_constant(ZPageSizeMinShift) \ + declare_constant(ZObjectAlignmentSmallShift) \ + declare_constant(ZObjectAlignmentMediumShift) \ + declare_constant(ZObjectAlignmentLargeShift) + +#define VM_LONG_CONSTANTS_Z(declare_constant, declare_constant_with_value) \ + declare_constant(ZAddressGoodMask) \ + declare_constant(ZAddressWeakBadMask) \ + declare_constant(ZAddressOffsetMask) + +#define VM_TYPES_Z(declare_type, \ + declare_toplevel_type) \ + \ + declare_type(ZCollectedHeap, CollectedHeap) \ + \ + declare_toplevel_type(ZHeap) \ + declare_toplevel_type(ZPage) \ + declare_toplevel_type(ZPageAllocator) \ + declare_toplevel_type(ZPageTable) \ + declare_toplevel_type(ZPageTableEntry) \ + declare_toplevel_type(ZAddressRangeMapForPageTable) \ + declare_toplevel_type(ZVirtualMemory) \ + declare_toplevel_type(ZForwardingTable) \ + declare_toplevel_type(ZForwardingTableEntry) \ + declare_toplevel_type(ZPhysicalMemoryManager) + +#endif // SHARE_VM_GC_Z_VMSTRUCTS_Z_HPP --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddress.java 2018-01-13 12:11:32.928121356 +0900 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.debugger.OopHandle; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.types.TypeDataBase; +import sun.jvm.hotspot.types.WrongTypeException; + +class ZAddress { + + private static long ZAddressWeakBadMask; + private static long ZAddressGoodMask; + private static long ZAddressOffsetMask; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { + ZAddressWeakBadMask = db.lookupLongConstant("ZAddressWeakBadMask").longValue(); + ZAddressGoodMask = db.lookupLongConstant("ZAddressGoodMask").longValue(); + ZAddressOffsetMask = db.lookupLongConstant("ZAddressOffsetMask").longValue(); + } + + static long as_long(Address value) { + if (value == null) { + return 0; + } + return value.asLongValue(); + }; + + static boolean is_null(Address value) { + return value == null; + } + + static boolean is_weak_bad(Address value) { + return (as_long(value) & ZAddressWeakBadMask) != 0; + } + + static boolean is_weak_good(Address value) { + return !is_weak_bad(value) && !is_null(value); + } + + static boolean is_weak_good_or_null(Address value) { + return !is_weak_bad(value); + } + + static Address offset(Address address) { + return address.andWithMask(ZAddressOffsetMask); + } + + static Address address(Address addr) { + // TODO: Linux-specific - We don't use a heap base on Linux + return ZOop.to_address(addr); + } + + static Address good(Address value) { + return address(offset(value).orWithMask(ZAddressGoodMask)); + } + + static Address good_or_null(Address value) { + return is_null(value) ? value : good(value); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddressRangeMapForPageTable.java 2018-01-13 12:11:33.749123579 +0900 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.types.AddressField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +class ZAddressRangeMapForPageTable extends VMObject { + private static AddressField mapField; + + private static int ZPageSizeMinShift; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZAddressRangeMapForPageTable"); + + mapField = type.getAddressField("_map"); + ZPageSizeMinShift = db.lookupIntConstant("ZPageSizeMinShift").intValue(); + } + + public ZAddressRangeMapForPageTable(Address addr) { + super(addr); + } + + private Address map() { + return mapField.getValue(addr); + } + + private long index_for_addr(Address addr) { + long index = ZAddress.offset(addr).asLongValue() >> ZPageSizeMinShift; + + return index; + } + + Address get(Address addr) { + long index = index_for_addr(addr); + + return map().getAddressAt(index * VM.getVM().getBytesPerLong()); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZBarrier.java 2018-01-13 12:11:34.570125802 +0900 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.types.TypeDataBase; +import sun.jvm.hotspot.types.WrongTypeException; + +class ZBarrier { + + private static int ZGlobalPhase; + private static int ZPhaseRelocate; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { + ZGlobalPhase = db.lookupIntConstant("ZGlobalPhase").intValue(); + ZPhaseRelocate = db.lookupIntConstant("ZPhaseRelocate").intValue(); + } + + private static boolean is_weak_good_or_null_fast_path(Address addr) { + return ZAddress.is_weak_good_or_null(addr); + } + + private static Address weak_load_barrier_on_oop_slow_path(Address addr) { + return ZAddress.is_weak_good(addr) ? ZAddress.good(addr) : relocate_or_remap(addr); + } + + private static boolean during_relocate() { + return ZGlobalPhase == ZPhaseRelocate; + } + + private static Address relocate(Address addr) { + ZHeap heap = zheap(); + if (heap.is_relocating(addr)) { + // Forward + return heap.relocate_object(addr); + } + + // Remap + return ZAddress.good(addr); + } + + private static ZHeap zheap() { + ZCollectedHeap zCollectedHeap = (ZCollectedHeap)VM.getVM().getUniverse().heap(); + return zCollectedHeap.heap(); + } + + private static Address remap(Address addr) { + ZHeap heap = zheap(); + if (heap.is_relocating(addr)) { + // Forward + return heap.forward_object(addr); + } + + // Remap + return ZAddress.good(addr); + } + + private static Address relocate_or_remap(Address addr) { + return during_relocate() ? relocate(addr) : remap(addr); + } + + static Address weak_barrier(Address o) { + // Fast path + if (is_weak_good_or_null_fast_path(o)) { + // Return the good address instead of the weak good address + // to ensure that the currently active heap view is used. + return ZAddress.good_or_null(o); + } + + // Slow path + return weak_load_barrier_on_oop_slow_path(o); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZCollectedHeap.java 2018-01-13 12:11:35.395128035 +0900 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017, 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import java.io.PrintStream; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.debugger.OopHandle; +import sun.jvm.hotspot.gc.shared.CollectedHeap; +import sun.jvm.hotspot.gc.shared.CollectedHeapName; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObjectFactory; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +// Mirror class for ZCollectedHeap. + +public class ZCollectedHeap extends CollectedHeap { + + private static long zHeapFieldOffset; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZCollectedHeap"); + + zHeapFieldOffset = type.getAddressField("_heap").getOffset(); + } + + public ZHeap heap() { + Address heapAddr = addr.addOffsetTo(zHeapFieldOffset); + return (ZHeap)VMObjectFactory.newObject(ZHeap.class, heapAddr); + } + + @Override + public CollectedHeapName kind() { + return CollectedHeapName.Z_COLLECTED_HEAP; + } + + @Override + public void printOn(PrintStream tty) { + heap().printOn(tty); + } + + public ZCollectedHeap(Address addr) { + super(addr); + } + + public OopHandle oop_load_at(OopHandle handle, long offset) { + assert(!VM.getVM().isCompressedOopsEnabled()); + + Address oopAddress = handle.getAddressAt(offset); + + oopAddress = ZBarrier.weak_barrier(oopAddress); + if (oopAddress == null) { + return null; + } + + return oopAddress.addOffsetToAsOopHandle(0); + } + + public String oopAddressDescription(OopHandle handle) { + Address origOop = ZOop.to_address(handle); + Address loadBarrieredOop = ZBarrier.weak_barrier(origOop); + if (!origOop.equals(loadBarrieredOop)) { + return origOop + " (" + loadBarrieredOop.toString() + ")"; + } else { + return handle.toString(); + } + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZForwardingTable.java 2018-01-13 12:11:39.814140000 +0900 @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.types.AddressField; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +class ZForwardingTable extends VMObject { + private static AddressField tableField; + private static CIntegerField sizeField; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZForwardingTable"); + + tableField = type.getAddressField("_table"); + sizeField = type.getCIntegerField("_size"); + } + + public ZForwardingTable(Address addr) { + super(addr); + } + + Address table() { + return tableField.getAddress(addr); + } + + long size() { + return sizeField.getJLong(addr); + } + + ZForwardingTableEntry at(ZForwardingTableCursor cursor) { + return new ZForwardingTableEntry(table().getAddressAt(cursor._value * VM.getVM().getBytesPerLong())); + } + + ZForwardingTableEntry first(long from_index, ZForwardingTableCursor cursor) { + long mask = size() - 1; + long hash = ZHash.uint32_to_uint32(from_index); + cursor._value = hash & mask; + return at(cursor); + } + + ZForwardingTableEntry next(ZForwardingTableCursor cursor) { + long mask = size() - 1; + cursor._value = (cursor._value + 1) & mask; + return at(cursor); + } + + ZForwardingTableEntry find(long from_index, ZForwardingTableCursor cursor) { + // Reading entries in the table races with the atomic cas done for + // insertion into the table. This is safe because each entry is at + // most updated once (from -1 to something else). + ZForwardingTableEntry entry = first(from_index, cursor); + while (!entry.is_empty()) { + if (entry.from_index() == from_index) { + // Match found, return matching entry + return entry; + } + + entry = next(cursor); + } + + // Match not found, return empty entry + return entry; + } + + ZForwardingTableEntry find(long from_index) { + ZForwardingTableCursor dummy = new ZForwardingTableCursor(); + return find(from_index, dummy); + } + + void dump() { + long s = size(); + long count = 0; + System.out.println("Dumping ZForwardingTable[" + s + "]:"); + ZForwardingTableCursor cursor = new ZForwardingTableCursor(); + for (long i = 0; i < s; i++) { + cursor._value = i; + ZForwardingTableEntry entry = at(cursor); + if (!entry.is_empty()) { + long hash = ZHash.uint32_to_uint32(entry.from_index()); + System.out.println(i + " " + count + " " + entry + " hash: " + hash + " masked_hash: " + (hash & (s - 1))); + count++; + } + } + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZForwardingTableCursor.java 2018-01-13 12:11:47.434160632 +0900 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +class ZForwardingTableCursor { + long _value; +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZForwardingTableEntry.java 2018-01-13 12:11:55.086181351 +0900 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; + +class ZForwardingTableEntry { + private Address entry; + + ZForwardingTableEntry(Address addr) { + entry = addr; + } + + private static long empty() { + return ~0L; + } + + boolean is_empty() { + return entry.asLongValue() == empty(); + } + + Address to_offset() { + return entry.andWithMask((1L << 42) - 1); + } + + long from_index() { + return entry.asLongValue() >>> 42; + } + + public String toString() { + return entry + " - from_index: " + from_index() + " to_offset: " + to_offset(); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHash.java 2018-01-13 12:12:02.658201853 +0900 @@ -0,0 +1,41 @@ +/* + * 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +class ZHash { + private static long uint32(long value) { + return value & 0xFFFFFFFFL; + } + + static long uint32_to_uint32(long key) { + key = uint32(~key + (key << 15)); + key = uint32(key ^ (key >> 12)); + key = uint32(key + (key << 2)); + key = uint32(key ^ (key >> 4)); + key = uint32(key * 2057); + key = uint32(key ^ (key >> 16)); + return key; + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java 2018-01-13 12:12:06.849213200 +0900 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017, 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import java.io.PrintStream; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.runtime.VMObjectFactory; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +// Mirror class for ZHeap + +public class ZHeap extends VMObject { + + private static long pageAllocatorFieldOffset; + private static long pageTableFieldOffset; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZHeap"); + + pageAllocatorFieldOffset = type.getAddressField("_page_allocator").getOffset(); + pageTableFieldOffset = type.getAddressField("_pagetable").getOffset(); + } + + private ZPageAllocator pageAllocator() { + Address pageAllocatorAddr = addr.addOffsetTo(pageAllocatorFieldOffset); + return (ZPageAllocator)VMObjectFactory.newObject(ZPageAllocator.class, pageAllocatorAddr); + } + + ZPageTable pageTable() { + return (ZPageTable)VMObjectFactory.newObject(ZPageTable.class, addr.addOffsetTo(pageTableFieldOffset)); + } + + public long maxCapacity() { + return pageAllocator().maxCapacity(); + } + + public long capacity() { + return pageAllocator().capacity(); + } + + public long used() { + return pageAllocator().used(); + } + + boolean is_relocating(Address o) { + return pageTable().is_relocating(o); + } + + Address forward_object(Address addr) { + ZPage page = pageTable().get(addr); + return page.forward_object(addr); + } + + Address relocate_object(Address addr) { + ZPage page = pageTable().get(addr); + return page.relocate_object(addr); + } + + public void printOn(PrintStream tty) { + tty.print(" ZHeap "); + tty.print("used " + (used() / 1024 / 1024) + "M, "); + tty.print("capacity " + (capacity() / 1024 / 1024) + "M, "); + tty.println("max capacity " + (maxCapacity() / 1024 / 1024) + "M"); + } + + public ZHeap(Address addr) { + super(addr); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZOop.java 2018-01-13 12:12:07.667215415 +0900 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; + +class ZOop { + private static final long REMOVE_MSB_MASK = Long.MAX_VALUE; + + static Address to_address(Address oop) { + // If the value of an Address becomes 0, null is returned instead of an Address. + // Start with a one-bit address and as a last step, remove that bit. + if ((oop == null) || (oop.asLongValue() == 0L)) { + return null; + } else { + return oop.andWithMask(REMOVE_MSB_MASK); + } + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPage.java 2018-01-13 12:12:08.484217627 +0900 @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.runtime.VMObjectFactory; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +class ZPage extends VMObject { + private static CIntegerField typeField; + private static long virtualFieldOffset; + private static long forwardingFieldOffset; + private static byte ZPageTypeSmall; + private static byte ZPageTypeMedium; + private static byte ZPageTypeLarge; + private static int ZObjectAlignmentSmallShift; + private static int ZObjectAlignmentMediumShift; + private static int ZObjectAlignmentLargeShift; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZPage"); + + typeField = type.getCIntegerField("_type"); + virtualFieldOffset = type.getField("_virtual").getOffset(); + forwardingFieldOffset = type.getField("_forwarding").getOffset(); + + ZPageTypeSmall = db.lookupIntConstant("ZPageTypeSmall").byteValue(); + ZPageTypeMedium = db.lookupIntConstant("ZPageTypeMedium").byteValue(); + ZPageTypeLarge = db.lookupIntConstant("ZPageTypeLarge").byteValue(); + ZObjectAlignmentSmallShift = db.lookupIntConstant("ZObjectAlignmentSmallShift").intValue(); + ZObjectAlignmentMediumShift = db.lookupIntConstant("ZObjectAlignmentMediumShift").intValue(); + ZObjectAlignmentLargeShift = db.lookupIntConstant("ZObjectAlignmentLargeShift").intValue(); + } + + ZPage(Address addr) { + super(addr); + } + + private byte type() { + return typeField.getJByte(addr); + } + + private ZVirtualMemory virtual() { + return (ZVirtualMemory)VMObjectFactory.newObject(ZVirtualMemory.class, addr.addOffsetTo(virtualFieldOffset)); + } + + private ZForwardingTable forwarding() { + return (ZForwardingTable)VMObjectFactory.newObject(ZForwardingTable.class, addr.addOffsetTo(forwardingFieldOffset)); + } + + private long start() { + return virtual().start(); + } + + Address forward_object(Address from) { + // Lookup address in forwarding table + long from_offset = ZAddress.offset(from).asLongValue(); + long from_index = (from_offset - start()) >> object_alignment_shift(); + ZForwardingTableEntry entry = forwarding().find(from_index); + assert(!entry.is_empty()); + assert(entry.from_index() == from_index); + + return ZAddress.good(entry.to_offset()); + } + + Address relocate_object(Address from) { + // Lookup address in forwarding table + long from_offset = ZAddress.offset(from).asLongValue(); + long from_index = (from_offset - start()) >> object_alignment_shift(); + ZForwardingTableEntry entry = forwarding().find(from_index); + if (!entry.is_empty() && entry.from_index() == from_index) { + return ZAddress.good(entry.to_offset()); + } + + // There's no relocate operation in the SA. + return ZAddress.good(from); + } + + + long object_alignment_shift() { + if (type() == ZPageTypeSmall) { + return ZObjectAlignmentSmallShift; + } else if (type() == ZPageTypeMedium) { + return ZObjectAlignmentMediumShift; + } else { + assert(type() == ZPageTypeLarge); + return ZObjectAlignmentLargeShift; + } + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageAllocator.java 2018-01-13 12:12:12.673228969 +0900 @@ -0,0 +1,74 @@ +/* + * 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.runtime.VMObjectFactory; +import sun.jvm.hotspot.types.AddressField; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +// Mirror class for ZPageAllocator + +public class ZPageAllocator extends VMObject { + + private static AddressField physicalField; + private static CIntegerField usedField; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZPageAllocator"); + + physicalField = type.getAddressField("_physical"); + usedField = type.getCIntegerField("_used"); + } + + private ZPhysicalMemoryManager physical() { + Address physicalAddr = physicalField.getValue(addr); + return (ZPhysicalMemoryManager)VMObjectFactory.newObject(ZPhysicalMemoryManager.class, physicalAddr); + } + + public long maxCapacity() { + return physical().maxCapacity(); + } + + public long capacity() { + return physical().capacity(); + } + + public long used() { + return usedField.getValue(addr); + } + + public ZPageAllocator(Address addr) { + super(addr); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTable.java 2018-01-13 12:12:16.911240444 +0900 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.runtime.VMObjectFactory; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +class ZPageTable extends VMObject { + private static long mapFieldOffset; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZPageTable"); + + mapFieldOffset = type.getAddressField("_map").getOffset(); + } + + private ZAddressRangeMapForPageTable map() { + return (ZAddressRangeMapForPageTable)VMObjectFactory.newObject(ZAddressRangeMapForPageTable.class, addr.addOffsetTo(mapFieldOffset)); + } + + private ZPageTableEntry getEntry(Address o) { + return new ZPageTableEntry(map().get(o)); + } + + ZPage get(Address o) { + return getEntry(o).page(); + } + + boolean is_relocating(Address o) { + return getEntry(o).relocating(); + } + + ZPageTable(Address addr) { + super(addr); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTableEntry.java 2018-01-13 12:12:17.730242661 +0900 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VMObjectFactory; + +class ZPageTableEntry { + Address entry; + + ZPage page() { + return (ZPage)VMObjectFactory.newObject(ZPage.class, entry.andWithMask(~1L)); + } + + boolean relocating() { + return (entry.asLongValue() & 1) == 1; + } + + ZPageTableEntry(Address address) { + entry = address; + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPhysicalMemoryManager.java 2018-01-13 12:12:21.948254082 +0900 @@ -0,0 +1,64 @@ +/* + * 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +// Mirror class for ZPhysicalMemoryManager + +public class ZPhysicalMemoryManager extends VMObject { + + private static CIntegerField capacityField; + + private static CIntegerField maxCapacityField; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZPhysicalMemoryManager"); + + capacityField = type.getCIntegerField("_capacity"); + maxCapacityField = type.getCIntegerField("_max_capacity"); + } + + public long capacity() { + return capacityField.getValue(addr); + } + + public long maxCapacity() { + return maxCapacityField.getValue(addr); + } + + public ZPhysicalMemoryManager(Address addr) { + super(addr); + } +} --- /dev/null 2018-01-13 11:40:43.273012900 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZVirtualMemory.java 2018-01-13 12:12:29.595274787 +0900 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, 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. + * + */ + +package sun.jvm.hotspot.gc.z; + +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObject; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +class ZVirtualMemory extends VMObject { + private static CIntegerField startField; + private static CIntegerField endField; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZVirtualMemory"); + + startField = type.getCIntegerField("_start"); + endField = type.getCIntegerField("_end"); + } + + long start() { + return startField.getJLong(addr); + } + + long end() { + return endField.getJLong(addr); + } + + ZVirtualMemory(Address addr) { + super(addr); + } +}