--- old/src/hotspot/share/gc/z/zAddressRangeMap.hpp 2018-01-17 11:44:01.551379015 +0900 +++ new/src/hotspot/share/gc/z/zAddressRangeMap.hpp 2018-01-17 11:44:01.404376506 +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-17 11:44:01.861384308 +0900 +++ new/src/hotspot/share/gc/z/zCollectedHeap.hpp 2018-01-17 11:44:01.719381883 +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-17 11:44:02.171389600 +0900 +++ new/src/hotspot/share/gc/z/zForwardingTable.hpp 2018-01-17 11:44:02.029387176 +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-17 11:44:02.502395251 +0900 +++ new/src/hotspot/share/gc/z/zHeap.hpp 2018-01-17 11:44:02.357392776 +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-17 11:44:02.818400646 +0900 +++ new/src/hotspot/share/gc/z/zPage.hpp 2018-01-17 11:44:02.679398273 +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-17 11:44:03.120405802 +0900 +++ new/src/hotspot/share/gc/z/zPageAllocator.hpp 2018-01-17 11:44:02.982403446 +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-17 11:44:03.422410958 +0900 +++ new/src/hotspot/share/gc/z/zPageTable.hpp 2018-01-17 11:44:03.284408602 +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-17 11:44:03.723416097 +0900 +++ new/src/hotspot/share/gc/z/zPhysicalMemory.hpp 2018-01-17 11:44:03.585413741 +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-17 11:44:04.029421322 +0900 +++ new/src/hotspot/share/gc/z/zVirtualMemory.hpp 2018-01-17 11:44:03.890418948 +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-17 11:44:04.340426631 +0900 +++ new/src/hotspot/share/runtime/vmStructs.cpp 2018-01-17 11:44:04.200424241 +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,11 @@ 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 +3256,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 +3309,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 +3385,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-17 11:44:04.691432624 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeap.java 2018-01-17 11:44:04.551430234 +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-17 11:44:05.009438053 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java 2018-01-17 11:44:04.864435577 +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-17 11:44:05.323443414 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java 2018-01-17 11:44:05.176440904 +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-17 11:44:05.717450141 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Oop.java 2018-01-17 11:44:05.576447733 +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-17 11:44:06.080456338 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/OopField.java 2018-01-17 11:44:05.922453641 +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-17 09:16:53.328430355 +0900 +++ new/src/hotspot/share/gc/z/vmStructs_z.cpp 2018-01-17 11:44:06.269459565 +0900 @@ -0,0 +1,38 @@ +/* + * 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. + * + */ + +#include "precompiled.hpp" +#include "gc/z/vmStructs_z.hpp" + +ZGlobalsForVMStructs::ZGlobalsForVMStructs() : + _ZGlobalPhase(&ZGlobalPhase), + _ZAddressGoodMask(&ZAddressGoodMask), + _ZAddressBadMask(&ZAddressBadMask), + _ZAddressWeakBadMask(&ZAddressWeakBadMask), + _ZObjectAlignmentSmallShift(&ZObjectAlignmentSmallShift), + _ZObjectAlignmentSmall(&ZObjectAlignmentSmall) { +} + +ZGlobalsForVMStructs ZGlobalsForVMStructs::_instance; +ZGlobalsForVMStructs* ZGlobalsForVMStructs::_instance_p = &ZGlobalsForVMStructs::_instance; --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/hotspot/share/gc/z/vmStructs_z.hpp 2018-01-17 11:44:06.590465045 +0900 @@ -0,0 +1,121 @@ +/* + * 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" + +// Expose some ZGC globals to the SA agent. +class ZGlobalsForVMStructs { + static ZGlobalsForVMStructs _instance; + +public: + static ZGlobalsForVMStructs* _instance_p; + + ZGlobalsForVMStructs(); + + uint32_t* _ZGlobalPhase; + + uintptr_t* _ZAddressGoodMask; + uintptr_t* _ZAddressBadMask; + uintptr_t* _ZAddressWeakBadMask; + + const int* _ZObjectAlignmentSmallShift; + const int* _ZObjectAlignmentSmall; +}; + + +typedef ZAddressRangeMap ZAddressRangeMapForPageTable; + +#define VM_STRUCTS_Z(nonstatic_field, static_field) \ + \ + static_field(ZGlobalsForVMStructs, _instance_p, ZGlobalsForVMStructs*) \ + nonstatic_field(ZGlobalsForVMStructs, _ZGlobalPhase, uint32_t*) \ + nonstatic_field(ZGlobalsForVMStructs, _ZAddressGoodMask, uintptr_t*) \ + nonstatic_field(ZGlobalsForVMStructs, _ZAddressBadMask, uintptr_t*) \ + nonstatic_field(ZGlobalsForVMStructs, _ZAddressWeakBadMask, uintptr_t*) \ + nonstatic_field(ZGlobalsForVMStructs, _ZObjectAlignmentSmallShift, const int*) \ + nonstatic_field(ZGlobalsForVMStructs, _ZObjectAlignmentSmall, const int*) \ + \ + 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(ZPhaseRelocate) \ + declare_constant(ZPageTypeSmall) \ + declare_constant(ZPageTypeMedium) \ + declare_constant(ZPageTypeLarge) + +#define VM_LONG_CONSTANTS_Z(declare_constant, declare_constant_with_value) \ + declare_constant(ZPlatformPageSizeSmallShift) \ + declare_constant(ZPlatformAddressOffsetBits) \ + declare_constant(ZAddressOffsetShift) + +#define VM_TYPES_Z(declare_type, \ + declare_toplevel_type) \ + \ + declare_toplevel_type(ZGlobalsForVMStructs) \ + \ + 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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddress.java 2018-01-17 11:44:06.904470406 +0900 @@ -0,0 +1,77 @@ +/* + * 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 ZAddress { + + 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) & ZGlobals.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 long offset(Address address) { + return as_long(address) & ZGlobals.ZAddressOffsetMask; + } + + static Address address(long value) { + Address result = ZOop.to_address(value); + VM vm = VM.getVM(); + + if (vm.getOS().equals("solaris") && vm.getCPU().equals("sparc")) { + result.orWithMask(ZGlobals.ZAddressSpaceStart); + } + + return result; + } + + static Address good(Address value) { + return address(offset(value) | ZGlobals.ZAddressGoodMask()); + } + + static Address good_or_null(Address value) { + return is_null(value) ? value : good(value); + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddressRangeMapForPageTable.java 2018-01-17 11:44:07.220475801 +0900 @@ -0,0 +1,68 @@ +/* + * 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; + +public class ZAddressRangeMapForPageTable extends VMObject { + private static AddressField mapField; + + private static long AddressRangeShift = ZGlobals.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"); + } + + 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) >> AddressRangeShift; + + return index; + } + + Address get(Address addr) { + long index = index_for_addr(addr); + + return map().getAddressAt(index * VM.getVM().getBytesPerLong()); + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZBarrier.java 2018-01-17 11:44:07.559481589 +0900 @@ -0,0 +1,85 @@ +/* + * 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 ZBarrier { + 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 ZGlobals.ZGlobalPhase() == ZGlobals.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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZCollectedHeap.java 2018-01-17 11:44:07.883487120 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZForwardingTable.java 2018-01-17 11:44:08.198492498 +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; + +public 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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZForwardingTableCursor.java 2018-01-17 11:44:08.516497928 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZForwardingTableEntry.java 2018-01-17 11:44:08.829503272 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZGlobals.java 2018-01-17 11:44:09.142508615 +0900 @@ -0,0 +1,115 @@ +/* + * 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.runtime.VM; +import sun.jvm.hotspot.types.Field; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +public class ZGlobals { + private static Field instanceField; + + public static int ZPhaseRelocate; + + public static byte ZPageTypeSmall; + public static byte ZPageTypeMedium; + public static byte ZPageTypeLarge; + + public static long ZPlatformPageSizeSmallShift; + public static long ZPlatformAddressOffsetBits; + + public static long ZAddressOffsetShift; + public static long ZAddressSpaceStart; + + // Page size shifts + public static int ZPageSizeSmallShift; + public static int ZPageSizeMediumShift; + public static int ZPageSizeMinShift; + + public static int ZObjectAlignmentMediumShift; + public static int ZObjectAlignmentLargeShift; + + public static long ZAddressOffsetBits; + public static long ZAddressOffsetMask; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZGlobalsForVMStructs"); + + instanceField = type.getField("_instance_p"); + + ZPhaseRelocate = db.lookupIntConstant("ZPhaseRelocate").intValue(); + ZPageTypeSmall = db.lookupIntConstant("ZPageTypeSmall").byteValue(); + ZPageTypeMedium = db.lookupIntConstant("ZPageTypeMedium").byteValue(); + ZPageTypeLarge = db.lookupIntConstant("ZPageTypeLarge").byteValue(); + + ZAddressOffsetShift = db.lookupLongConstant("ZAddressOffsetShift").longValue(); + ZPlatformPageSizeSmallShift = db.lookupLongConstant("ZPlatformPageSizeSmallShift").longValue(); + ZPlatformAddressOffsetBits = db.lookupLongConstant("ZPlatformAddressOffsetBits").longValue(); + + long ZPlatformAddressSpaceStart = 1 << ZPlatformAddressOffsetBits; + ZAddressSpaceStart = ZPlatformAddressSpaceStart; + + ZPageSizeSmallShift = (int)ZPlatformPageSizeSmallShift; + ZPageSizeMediumShift = ZPageSizeSmallShift + 4; + ZPageSizeMinShift = ZPageSizeSmallShift; + ZObjectAlignmentMediumShift = ZPageSizeMediumShift - 13; // 8192 objects per page + ZObjectAlignmentLargeShift = ZPageSizeSmallShift; + ZAddressOffsetBits = ZPlatformAddressOffsetBits; + ZAddressOffsetMask = ((1L << ZAddressOffsetBits) - 1) << ZAddressOffsetShift; + } + + private static ZGlobalsForVMStructs instance() { + return new ZGlobalsForVMStructs(instanceField.getAddress()); + } + + public static int ZGlobalPhase() { + return instance().ZGlobalPhase(); + } + + public static long ZAddressGoodMask() { + return instance().ZAddressGoodMask(); + } + + public static long ZAddressBadMask() { + return instance().ZAddressBadMask(); + } + + public static long ZAddressWeakBadMask() { + return instance().ZAddressWeakBadMask(); + } + + public static int ZObjectAlignmentSmallShift() { + return instance().ZObjectAlignmentSmallShift(); + } + + public static int ZObjectAlignmentSmall() { + return instance().ZObjectAlignmentSmall(); + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZGlobalsForVMStructs.java 2018-01-17 11:44:09.457513993 +0900 @@ -0,0 +1,84 @@ +/* + * 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.AddressField; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; + +class ZGlobalsForVMStructs extends VMObject { + private static AddressField ZGlobalPhaseField; + private static AddressField ZAddressGoodMaskField; + private static AddressField ZAddressBadMaskField; + private static AddressField ZAddressWeakBadMaskField; + private static AddressField ZObjectAlignmentSmallShiftField; + private static AddressField ZObjectAlignmentSmallField; + + static { + VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + static private synchronized void initialize(TypeDataBase db) { + Type type = db.lookupType("ZGlobalsForVMStructs"); + + ZGlobalPhaseField = type.getAddressField("_ZGlobalPhase"); + ZAddressGoodMaskField = type.getAddressField("_ZAddressGoodMask"); + ZAddressBadMaskField = type.getAddressField("_ZAddressBadMask"); + ZAddressWeakBadMaskField = type.getAddressField("_ZAddressWeakBadMask"); + ZObjectAlignmentSmallShiftField = type.getAddressField("_ZObjectAlignmentSmallShift"); + ZObjectAlignmentSmallField = type.getAddressField("_ZObjectAlignmentSmall"); + } + + ZGlobalsForVMStructs(Address addr) { + super(addr); + } + + int ZGlobalPhase() { + return ZGlobalPhaseField.getValue(addr).getJIntAt(0); + } + + long ZAddressGoodMask() { + return ZAddressGoodMaskField.getValue(addr).getJLongAt(0); + } + + long ZAddressBadMask() { + return ZAddressBadMaskField.getValue(addr).getJLongAt(0); + } + + long ZAddressWeakBadMask() { + return ZAddressWeakBadMaskField.getValue(addr).getJLongAt(0); + } + + int ZObjectAlignmentSmallShift() { + return ZObjectAlignmentSmallShiftField.getValue(addr).getJIntAt(0); + } + + int ZObjectAlignmentSmall() { + return ZObjectAlignmentSmallField.getValue(addr).getJIntAt(0); + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHash.java 2018-01-17 11:44:09.779519491 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java 2018-01-17 11:44:10.103525022 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZOop.java 2018-01-17 11:44:10.430530605 +0900 @@ -0,0 +1,48 @@ +/* + * 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; + +class ZOop { + private static final long MSB = ~0L ^ (~0L >>> 1); + + private static Address msbAddress() { + return VM.getVM().getUniverse().heap().start().orWithMask(MSB).andWithMask(MSB); + } + + static Address to_address(long value) { + // 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. + Address oneAddress = msbAddress(); + return oneAddress.orWithMask(value).xorWithMask(ZAddress.as_long(oneAddress)); + } + + static Address to_address(OopHandle oop) { + return to_address(ZAddress.as_long(oop)); + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPage.java 2018-01-17 11:44:10.757536188 +0900 @@ -0,0 +1,107 @@ +/* + * 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; + +public class ZPage extends VMObject { + private static CIntegerField typeField; + private static long virtualFieldOffset; + private static long forwardingFieldOffset; + + 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(); + } + + public 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); + 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); + 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() == ZGlobals.ZPageTypeSmall) { + return ZGlobals.ZObjectAlignmentSmallShift(); + } else if (type() == ZGlobals.ZPageTypeMedium) { + return ZGlobals.ZObjectAlignmentMediumShift; + } else { + assert(type() == ZGlobals.ZPageTypeLarge); + return ZGlobals.ZObjectAlignmentLargeShift; + } + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageAllocator.java 2018-01-17 11:44:11.078541668 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTable.java 2018-01-17 11:44:11.405547251 +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; + +public 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(); + } + + public ZPageTable(Address addr) { + super(addr); + } +} --- /dev/null 2018-01-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTableEntry.java 2018-01-17 11:44:11.726552732 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPhysicalMemoryManager.java 2018-01-17 11:44:12.049558246 +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-17 09:16:53.328430355 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZVirtualMemory.java 2018-01-17 11:44:12.374563795 +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; + +public 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); + } + + public ZVirtualMemory(Address addr) { + super(addr); + } +}