Skip to content

Commit f3c85a9

Browse files
committed
NUMA support for Serviceability Agent
1 parent 751ebf2 commit f3c85a9

File tree

6 files changed

+73
-5
lines changed

6 files changed

+73
-5
lines changed

src/hotspot/share/gc/z/vmStructs_z.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "gc/z/zForwarding.hpp"
3030
#include "gc/z/zGranuleMap.hpp"
3131
#include "gc/z/zHeap.hpp"
32+
#include "gc/z/zNUMA.hpp"
3233
#include "gc/z/zPageAllocator.hpp"
3334
#include "gc/z/zPageType.hpp"
3435
#include "gc/z/zValue.hpp"
@@ -91,6 +92,7 @@ typedef ZValue<ZPerNUMAStorage, ZCacheState> ZPerNUMACacheState;
9192
nonstatic_field(ZPageAllocator, _max_capacity, const size_t) \
9293
nonstatic_field(ZPageAllocator, _states, ZPerNUMACacheState) \
9394
\
95+
static_field(ZNUMA, _count, uint32_t) \
9496
nonstatic_field(ZPerNUMACacheState, _addr, const uintptr_t) \
9597
\
9698
volatile_nonstatic_field(ZCacheState, _capacity, size_t) \
@@ -140,6 +142,7 @@ typedef ZValue<ZPerNUMAStorage, ZCacheState> ZPerNUMACacheState;
140142
declare_toplevel_type(ZPage) \
141143
declare_toplevel_type(ZPageType) \
142144
declare_toplevel_type(ZPageAllocator) \
145+
declare_toplevel_type(ZNUMA) \
143146
declare_toplevel_type(ZPerNUMACacheState) \
144147
declare_toplevel_type(ZCacheState) \
145148
declare_toplevel_type(ZPageTable) \

src/hotspot/share/gc/z/zNUMA.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
#ifndef SHARE_GC_Z_ZNUMA_HPP
2525
#define SHARE_GC_Z_ZNUMA_HPP
2626

27+
#include "gc/z/vmStructs_z.hpp"
2728
#include "memory/allStatic.hpp"
2829
#include "utilities/globalDefinitions.hpp"
2930

3031
class ZNUMA : public AllStatic {
32+
friend class VMStructs;
33+
3134
private:
3235
static bool _enabled;
3336
static uint32_t _count;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
package sun.jvm.hotspot.gc.z;
26+
27+
import sun.jvm.hotspot.runtime.VM;
28+
import sun.jvm.hotspot.types.CIntegerField;
29+
import sun.jvm.hotspot.types.Type;
30+
import sun.jvm.hotspot.types.TypeDataBase;
31+
32+
public class ZNUMA {
33+
34+
private static CIntegerField countField;
35+
36+
static {
37+
VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase()));
38+
}
39+
40+
private static synchronized void initialize(TypeDataBase db) {
41+
Type type = db.lookupType("ZNUMA");
42+
43+
countField = type.getCIntegerField("_count");
44+
}
45+
46+
public long count() {
47+
return countField.getValue();
48+
}
49+
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageAllocator.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ZPageAllocator extends VMObject {
3838

3939
private static CIntegerField maxCapacityField;
4040
private static long cacheStateFieldOffset;
41+
private static long numaCount;
4142

4243
static {
4344
VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase()));
@@ -48,6 +49,7 @@ private static synchronized void initialize(TypeDataBase db) {
4849

4950
maxCapacityField = type.getCIntegerField("_max_capacity");
5051
cacheStateFieldOffset = type.getAddressField("_states").getOffset();
52+
numaCount = (new ZNUMA()).count();
5153
}
5254

5355
private ZPerNUMACacheState states() {
@@ -60,11 +62,19 @@ public long maxCapacity() {
6062
}
6163

6264
public long capacity() {
63-
return states().value().capacity();
65+
long total_capacity = 0;
66+
for (int id = 0; id < numaCount; id++) {
67+
total_capacity += states().value(id).capacity();
68+
}
69+
return total_capacity;
6470
}
6571

6672
public long used() {
67-
return states().value().used();
73+
long total_used = 0;
74+
for (int id = 0; id < numaCount; id++) {
75+
total_used += states().value(id).used();
76+
}
77+
return total_used;
6878
}
6979

7080
public ZPageAllocator(Address addr) {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPerNUMACacheState.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class ZPerNUMACacheState extends VMObject {
3838

3939
private static AddressField addrField;
40+
private static long valueOffset = 4 * 1024; // 4K
4041

4142
static {
4243
VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase()));
@@ -47,9 +48,10 @@ private static synchronized void initialize(TypeDataBase db) {
4748
addrField = type.getAddressField("_addr");
4849
}
4950

50-
public ZCacheState value() {
51-
Address valueAddr = addrField.getValue(addr);
52-
return VMObjectFactory.newObject(ZCacheState.class, valueAddr);
51+
public ZCacheState value(long id) {
52+
Address valueArrayAddr = addrField.getValue(addr);
53+
Address cacheStateAddr = valueArrayAddr.addOffsetTo(id * valueOffset);
54+
return VMObjectFactory.newObject(ZCacheState.class, cacheStateAddr);
5355
}
5456

5557
public ZPerNUMACacheState(Address addr) {

test/hotspot/gtest/gc/z/test_zMapper_windows.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ZMapperTest : public Test {
7575

7676
ZSyscall::initialize();
7777
ZGlobalsPointers::initialize();
78+
ZNUMA::initialize();
7879

7980
// Fake a ZVirtualMemoryManager
8081
_vmm = (ZVirtualMemoryManager*)os::malloc(sizeof(ZVirtualMemoryManager), mtTest);

0 commit comments

Comments
 (0)