Skip to content

Commit 767262e

Browse files
committed
8292201: serviceability/sa/ClhsdbThreadContext.java fails with "'Thread "Common-Cleaner"' missing from stdout/stderr"
Reviewed-by: amenkov, sspitsyn
1 parent a366e82 commit 767262e

File tree

11 files changed

+73
-175
lines changed

11 files changed

+73
-175
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/AddressException.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,8 +31,8 @@ public AddressException(long addr) {
3131
this.addr = addr;
3232
}
3333

34-
public AddressException(String detail, long addr) {
35-
super(detail);
34+
public AddressException(String message, long addr) {
35+
super(message);
3636
this.addr = addr;
3737
}
3838

@@ -41,6 +41,11 @@ public long getAddress() {
4141
}
4242

4343
public String getMessage() {
44-
return Long.toHexString(addr);
44+
String msg = super.getMessage();
45+
if (msg != null) {
46+
return msg;
47+
} else {
48+
return Long.toHexString(addr);
49+
}
4550
}
4651
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/DebuggerBase.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public abstract class DebuggerBase implements Debugger {
6464
protected int narrowKlassShift; // shift to decode compressed klass ptrs.
6565
// Should be initialized if desired by calling initCache()
6666
private PageCache cache;
67+
private long pageSize;
6768

6869
// State for faster accessors that don't allocate memory on each read
6970
private boolean useFastAccessors;
@@ -177,6 +178,7 @@ public void putHeapConst(long heapOopSize, long klassPtrSize, long narrowOopBase
177178
cache but may not be overridden */
178179
protected final void initCache(long pageSize, long maxNumPages) {
179180
cache = new PageCache(pageSize, maxNumPages, new Fetcher());
181+
this.pageSize = pageSize;
180182
if (machDesc != null) {
181183
bigEndian = machDesc.isBigEndian();
182184
}
@@ -232,6 +234,19 @@ protected final byte[] readBytes(long address, long numBytes)
232234
}
233235
}
234236

237+
/** If an address for a 64-bit value starts on the last 32-bit word of a
238+
page, then we can't use the page cache to read it because it will cause
239+
an ArrayIndexOutOfBoundsException when reading past the end of the page. */
240+
private boolean canUsePageCacheFor64bitRead(long address) {
241+
long pageMask = ~(pageSize - 1);
242+
if ((address & pageMask) != ((address + 4) & pageMask)) {
243+
// This address starts on the last 32-bit word of the page.
244+
// Cannot use the page cache in that case.
245+
return false;
246+
}
247+
return true;
248+
}
249+
235250
public boolean readJBoolean(long address)
236251
throws UnmappedAddressException, UnalignedAddressException {
237252
checkJavaConfigured();
@@ -256,8 +271,6 @@ public byte readJByte(long address)
256271
}
257272
}
258273

259-
// NOTE: assumes value does not span pages (may be bad assumption on
260-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
261274
public char readJChar(long address)
262275
throws UnmappedAddressException, UnalignedAddressException {
263276
checkJavaConfigured();
@@ -270,22 +283,18 @@ public char readJChar(long address)
270283
}
271284
}
272285

273-
// NOTE: assumes value does not span pages (may be bad assumption on
274-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
275286
public double readJDouble(long address)
276287
throws UnmappedAddressException, UnalignedAddressException {
277288
checkJavaConfigured();
278289
utils.checkAlignment(address, jdoubleSize);
279-
if (useFastAccessors) {
290+
if (useFastAccessors && canUsePageCacheFor64bitRead(address)) {
280291
return cache.getDouble(address, bigEndian);
281292
} else {
282293
byte[] data = readBytes(address, jdoubleSize);
283294
return utils.dataToJDouble(data, jdoubleSize);
284295
}
285296
}
286297

287-
// NOTE: assumes value does not span pages (may be bad assumption on
288-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
289298
public float readJFloat(long address)
290299
throws UnmappedAddressException, UnalignedAddressException {
291300
checkJavaConfigured();
@@ -298,8 +307,6 @@ public float readJFloat(long address)
298307
}
299308
}
300309

301-
// NOTE: assumes value does not span pages (may be bad assumption on
302-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
303310
public int readJInt(long address)
304311
throws UnmappedAddressException, UnalignedAddressException {
305312
checkJavaConfigured();
@@ -312,22 +319,18 @@ public int readJInt(long address)
312319
}
313320
}
314321

315-
// NOTE: assumes value does not span pages (may be bad assumption on
316-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
317322
public long readJLong(long address)
318323
throws UnmappedAddressException, UnalignedAddressException {
319324
checkJavaConfigured();
320325
utils.checkAlignment(address, jlongSize);
321-
if (useFastAccessors) {
326+
if (useFastAccessors && canUsePageCacheFor64bitRead(address)) {
322327
return cache.getLong(address, bigEndian);
323328
} else {
324329
byte[] data = readBytes(address, jlongSize);
325330
return utils.dataToJLong(data, jlongSize);
326331
}
327332
}
328333

329-
// NOTE: assumes value does not span pages (may be bad assumption on
330-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
331334
public short readJShort(long address)
332335
throws UnmappedAddressException, UnalignedAddressException {
333336
checkJavaConfigured();
@@ -340,13 +343,11 @@ public short readJShort(long address)
340343
}
341344
}
342345

343-
// NOTE: assumes value does not span pages (may be bad assumption on
344-
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
345346
public long readCInteger(long address, long numBytes, boolean isUnsigned)
346347
throws UnmappedAddressException, UnalignedAddressException {
347348
checkConfigured();
348349
utils.checkAlignment(address, numBytes);
349-
if (useFastAccessors) {
350+
if (useFastAccessors && (numBytes != 8 || canUsePageCacheFor64bitRead(address))) {
350351
if (isUnsigned) {
351352
switch((int) numBytes) {
352353
case 1: return cache.getByte(address) & 0xFF;

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/DebuggerUtilities.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,10 +29,13 @@
2929
public class DebuggerUtilities {
3030
protected long addressSize;
3131
protected boolean isBigEndian;
32+
protected boolean supports32bitAlignmentOf64bitTypes;
3233

33-
public DebuggerUtilities(long addressSize, boolean isBigEndian) {
34+
public DebuggerUtilities(long addressSize, boolean isBigEndian,
35+
boolean supports32bitAlignmentOf64bitTypes) {
3436
this.addressSize = addressSize;
3537
this.isBigEndian = isBigEndian;
38+
this.supports32bitAlignmentOf64bitTypes = supports32bitAlignmentOf64bitTypes;
3639
}
3740

3841
public String addressValueToString(long address) {
@@ -53,6 +56,13 @@ public String addressValueToString(long address) {
5356
}
5457

5558
public void checkAlignment(long address, long alignment) {
59+
// Allow 32-bit alignment for 64-bit types on some hosts.
60+
if (supports32bitAlignmentOf64bitTypes) {
61+
if (address % 4 == 0) {
62+
return;
63+
}
64+
}
65+
5666
if (address % alignment != 0) {
5767
throw new UnalignedAddressException("Trying to read at address: " +
5868
addressValueToString(address) +

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/MachineDescription.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,4 +56,10 @@ the size in bytes is not legal for a C type (or can not be
5656
/** Indicates whether the underlying machine supports the LP64 data
5757
model (currently only SPARC/64). */
5858
public boolean isLP64();
59+
60+
/** Indicates whether the underlying machine supports 64-bit types
61+
that are only 32-bit aligned. */
62+
default public boolean supports32bitAlignmentOf64bitTypes() {
63+
return false;
64+
}
5965
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/MachineDescriptionIntelX86.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,4 +32,8 @@ public long getAddressSize() {
3232
public boolean isBigEndian() {
3333
return false;
3434
}
35+
36+
public boolean supports32bitAlignmentOf64bitTypes() {
37+
return true;
38+
}
3539
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,8 @@ public BsdDebuggerLocal(MachineDescription machDesc,
188188
boolean useCache) throws DebuggerException {
189189
this.machDesc = machDesc;
190190
utils = new DebuggerUtilities(machDesc.getAddressSize(),
191-
machDesc.isBigEndian()) {
192-
public void checkAlignment(long address, long alignment) {
193-
// Need to override default checkAlignment because we need to
194-
// relax alignment constraints on Bsd/x86
195-
if ( (address % alignment != 0)
196-
&&(alignment != 8 || address % 4 != 0)) {
197-
throw new UnalignedAddressException(
198-
"Trying to read at address: "
199-
+ addressValueToString(address)
200-
+ " with alignment: " + alignment,
201-
address);
202-
}
203-
}
204-
};
191+
machDesc.isBigEndian(),
192+
machDesc.supports32bitAlignmentOf64bitTypes());
205193

206194
if (useCache) {
207195
// This is a cache of 64k of 4K pages, or 256 MB.
@@ -484,30 +472,6 @@ public void doit(BsdDebuggerLocal debugger) {
484472
}
485473
}
486474

487-
/** Need to override this to relax alignment checks on x86. */
488-
public long readCInteger(long address, long numBytes, boolean isUnsigned)
489-
throws UnmappedAddressException, UnalignedAddressException {
490-
// Only slightly relaxed semantics -- this is a hack, but is
491-
// necessary on x86 where it seems the compiler is
492-
// putting some global 64-bit data on 32-bit boundaries
493-
if (numBytes == 8) {
494-
utils.checkAlignment(address, 4);
495-
} else {
496-
utils.checkAlignment(address, numBytes);
497-
}
498-
byte[] data = readBytes(address, numBytes);
499-
return utils.dataToCInteger(data, isUnsigned);
500-
}
501-
502-
// Overridden from DebuggerBase because we need to relax alignment
503-
// constraints on x86
504-
public long readJLong(long address)
505-
throws UnmappedAddressException, UnalignedAddressException {
506-
utils.checkAlignment(address, jintSize);
507-
byte[] data = readBytes(address, jlongSize);
508-
return utils.dataToJLong(data, jlongSize);
509-
}
510-
511475
//----------------------------------------------------------------------
512476
// Address access. Can not be package private, but should only be
513477
// accessed by the architecture-specific subpackages.

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,8 @@ public LinuxDebuggerLocal(MachineDescription machDesc,
207207
boolean useCache) throws DebuggerException {
208208
this.machDesc = machDesc;
209209
utils = new DebuggerUtilities(machDesc.getAddressSize(),
210-
machDesc.isBigEndian()) {
211-
public void checkAlignment(long address, long alignment) {
212-
// Need to override default checkAlignment because we need to
213-
// relax alignment constraints on Linux/x86
214-
if ( (address % alignment != 0)
215-
&&(alignment != 8 || address % 4 != 0)) {
216-
throw new UnalignedAddressException(
217-
"Trying to read at address: "
218-
+ addressValueToString(address)
219-
+ " with alignment: " + alignment,
220-
address);
221-
}
222-
}
223-
};
210+
machDesc.isBigEndian(),
211+
machDesc.supports32bitAlignmentOf64bitTypes());
224212

225213
if (useCache) {
226214
// This is a cache of 64k of 4K pages, or 256 MB.
@@ -541,30 +529,6 @@ public void doit(LinuxDebuggerLocal debugger) {
541529
}
542530
}
543531

544-
/** Need to override this to relax alignment checks on x86. */
545-
public long readCInteger(long address, long numBytes, boolean isUnsigned)
546-
throws UnmappedAddressException, UnalignedAddressException {
547-
// Only slightly relaxed semantics -- this is a hack, but is
548-
// necessary on x86 where it seems the compiler is
549-
// putting some global 64-bit data on 32-bit boundaries
550-
if (numBytes == 8) {
551-
utils.checkAlignment(address, 4);
552-
} else {
553-
utils.checkAlignment(address, numBytes);
554-
}
555-
byte[] data = readBytes(address, numBytes);
556-
return utils.dataToCInteger(data, isUnsigned);
557-
}
558-
559-
// Overridden from DebuggerBase because we need to relax alignment
560-
// constraints on x86
561-
public long readJLong(long address)
562-
throws UnmappedAddressException, UnalignedAddressException {
563-
utils.checkAlignment(address, jintSize);
564-
byte[] data = readBytes(address, jlongSize);
565-
return utils.dataToJLong(data, jlongSize);
566-
}
567-
568532
//----------------------------------------------------------------------
569533
// Address access. Can not be package private, but should only be
570534
// accessed by the architecture-specific subpackages.

0 commit comments

Comments
 (0)