Skip to content

Commit

Permalink
8292201: serviceability/sa/ClhsdbThreadContext.java fails with "'Thre…
Browse files Browse the repository at this point in the history
…ad "Common-Cleaner"' missing from stdout/stderr"

Reviewed-by: amenkov, sspitsyn
  • Loading branch information
plummercj committed Sep 3, 2022
1 parent a366e82 commit 767262e
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 175 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
Expand Down Expand Up @@ -31,8 +31,8 @@ public AddressException(long addr) {
this.addr = addr;
}

public AddressException(String detail, long addr) {
super(detail);
public AddressException(String message, long addr) {
super(message);
this.addr = addr;
}

Expand All @@ -41,6 +41,11 @@ public long getAddress() {
}

public String getMessage() {
return Long.toHexString(addr);
String msg = super.getMessage();
if (msg != null) {
return msg;
} else {
return Long.toHexString(addr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public abstract class DebuggerBase implements Debugger {
protected int narrowKlassShift; // shift to decode compressed klass ptrs.
// Should be initialized if desired by calling initCache()
private PageCache cache;
private long pageSize;

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

/** If an address for a 64-bit value starts on the last 32-bit word of a
page, then we can't use the page cache to read it because it will cause
an ArrayIndexOutOfBoundsException when reading past the end of the page. */
private boolean canUsePageCacheFor64bitRead(long address) {
long pageMask = ~(pageSize - 1);
if ((address & pageMask) != ((address + 4) & pageMask)) {
// This address starts on the last 32-bit word of the page.
// Cannot use the page cache in that case.
return false;
}
return true;
}

public boolean readJBoolean(long address)
throws UnmappedAddressException, UnalignedAddressException {
checkJavaConfigured();
Expand All @@ -256,8 +271,6 @@ public byte readJByte(long address)
}
}

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

// NOTE: assumes value does not span pages (may be bad assumption on
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
public double readJDouble(long address)
throws UnmappedAddressException, UnalignedAddressException {
checkJavaConfigured();
utils.checkAlignment(address, jdoubleSize);
if (useFastAccessors) {
if (useFastAccessors && canUsePageCacheFor64bitRead(address)) {
return cache.getDouble(address, bigEndian);
} else {
byte[] data = readBytes(address, jdoubleSize);
return utils.dataToJDouble(data, jdoubleSize);
}
}

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

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

// NOTE: assumes value does not span pages (may be bad assumption on
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
public long readJLong(long address)
throws UnmappedAddressException, UnalignedAddressException {
checkJavaConfigured();
utils.checkAlignment(address, jlongSize);
if (useFastAccessors) {
if (useFastAccessors && canUsePageCacheFor64bitRead(address)) {
return cache.getLong(address, bigEndian);
} else {
byte[] data = readBytes(address, jlongSize);
return utils.dataToJLong(data, jlongSize);
}
}

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

// NOTE: assumes value does not span pages (may be bad assumption on
// Solaris/x86; see unalignedAccessesOkay in DbxDebugger hierarchy)
public long readCInteger(long address, long numBytes, boolean isUnsigned)
throws UnmappedAddressException, UnalignedAddressException {
checkConfigured();
utils.checkAlignment(address, numBytes);
if (useFastAccessors) {
if (useFastAccessors && (numBytes != 8 || canUsePageCacheFor64bitRead(address))) {
if (isUnsigned) {
switch((int) numBytes) {
case 1: return cache.getByte(address) & 0xFF;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, 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
Expand Down Expand Up @@ -29,10 +29,13 @@
public class DebuggerUtilities {
protected long addressSize;
protected boolean isBigEndian;
protected boolean supports32bitAlignmentOf64bitTypes;

public DebuggerUtilities(long addressSize, boolean isBigEndian) {
public DebuggerUtilities(long addressSize, boolean isBigEndian,
boolean supports32bitAlignmentOf64bitTypes) {
this.addressSize = addressSize;
this.isBigEndian = isBigEndian;
this.supports32bitAlignmentOf64bitTypes = supports32bitAlignmentOf64bitTypes;
}

public String addressValueToString(long address) {
Expand All @@ -53,6 +56,13 @@ public String addressValueToString(long address) {
}

public void checkAlignment(long address, long alignment) {
// Allow 32-bit alignment for 64-bit types on some hosts.
if (supports32bitAlignmentOf64bitTypes) {
if (address % 4 == 0) {
return;
}
}

if (address % alignment != 0) {
throw new UnalignedAddressException("Trying to read at address: " +
addressValueToString(address) +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
Expand Down Expand Up @@ -56,4 +56,10 @@ the size in bytes is not legal for a C type (or can not be
/** Indicates whether the underlying machine supports the LP64 data
model (currently only SPARC/64). */
public boolean isLP64();

/** Indicates whether the underlying machine supports 64-bit types
that are only 32-bit aligned. */
default public boolean supports32bitAlignmentOf64bitTypes() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
Expand Down Expand Up @@ -32,4 +32,8 @@ public long getAddressSize() {
public boolean isBigEndian() {
return false;
}

public boolean supports32bitAlignmentOf64bitTypes() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,8 @@ public BsdDebuggerLocal(MachineDescription machDesc,
boolean useCache) throws DebuggerException {
this.machDesc = machDesc;
utils = new DebuggerUtilities(machDesc.getAddressSize(),
machDesc.isBigEndian()) {
public void checkAlignment(long address, long alignment) {
// Need to override default checkAlignment because we need to
// relax alignment constraints on Bsd/x86
if ( (address % alignment != 0)
&&(alignment != 8 || address % 4 != 0)) {
throw new UnalignedAddressException(
"Trying to read at address: "
+ addressValueToString(address)
+ " with alignment: " + alignment,
address);
}
}
};
machDesc.isBigEndian(),
machDesc.supports32bitAlignmentOf64bitTypes());

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

/** Need to override this to relax alignment checks on x86. */
public long readCInteger(long address, long numBytes, boolean isUnsigned)
throws UnmappedAddressException, UnalignedAddressException {
// Only slightly relaxed semantics -- this is a hack, but is
// necessary on x86 where it seems the compiler is
// putting some global 64-bit data on 32-bit boundaries
if (numBytes == 8) {
utils.checkAlignment(address, 4);
} else {
utils.checkAlignment(address, numBytes);
}
byte[] data = readBytes(address, numBytes);
return utils.dataToCInteger(data, isUnsigned);
}

// Overridden from DebuggerBase because we need to relax alignment
// constraints on x86
public long readJLong(long address)
throws UnmappedAddressException, UnalignedAddressException {
utils.checkAlignment(address, jintSize);
byte[] data = readBytes(address, jlongSize);
return utils.dataToJLong(data, jlongSize);
}

//----------------------------------------------------------------------
// Address access. Can not be package private, but should only be
// accessed by the architecture-specific subpackages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,8 @@ public LinuxDebuggerLocal(MachineDescription machDesc,
boolean useCache) throws DebuggerException {
this.machDesc = machDesc;
utils = new DebuggerUtilities(machDesc.getAddressSize(),
machDesc.isBigEndian()) {
public void checkAlignment(long address, long alignment) {
// Need to override default checkAlignment because we need to
// relax alignment constraints on Linux/x86
if ( (address % alignment != 0)
&&(alignment != 8 || address % 4 != 0)) {
throw new UnalignedAddressException(
"Trying to read at address: "
+ addressValueToString(address)
+ " with alignment: " + alignment,
address);
}
}
};
machDesc.isBigEndian(),
machDesc.supports32bitAlignmentOf64bitTypes());

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

/** Need to override this to relax alignment checks on x86. */
public long readCInteger(long address, long numBytes, boolean isUnsigned)
throws UnmappedAddressException, UnalignedAddressException {
// Only slightly relaxed semantics -- this is a hack, but is
// necessary on x86 where it seems the compiler is
// putting some global 64-bit data on 32-bit boundaries
if (numBytes == 8) {
utils.checkAlignment(address, 4);
} else {
utils.checkAlignment(address, numBytes);
}
byte[] data = readBytes(address, numBytes);
return utils.dataToCInteger(data, isUnsigned);
}

// Overridden from DebuggerBase because we need to relax alignment
// constraints on x86
public long readJLong(long address)
throws UnmappedAddressException, UnalignedAddressException {
utils.checkAlignment(address, jintSize);
byte[] data = readBytes(address, jlongSize);
return utils.dataToJLong(data, jlongSize);
}

//----------------------------------------------------------------------
// Address access. Can not be package private, but should only be
// accessed by the architecture-specific subpackages.
Expand Down

1 comment on commit 767262e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.