Skip to content

Commit

Permalink
7903352: JOL: Drop support for JDK 7
Browse files Browse the repository at this point in the history
  • Loading branch information
shipilev authored Oct 18, 2022
1 parent 76c554a commit 153c155
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [7, 8, 11, 17, 19-ea]
java: [8, 11, 17, 19-ea]
os: [ubuntu-20.04, windows-2022, macos-11]
fail-fast: false
name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ protected Object tryInstantiate(Class<?> klass) throws Exception {

private static Object makeDefaultValue(Class<?> type) {
if (type == boolean.class || type == Boolean.class) return Boolean.FALSE;
if (type == byte.class || type == Byte.class) return Byte.valueOf((byte) 0);
if (type == short.class || type == Short.class) return Short.valueOf((short)0);
if (type == char.class || type == Character.class) return Character.valueOf((char)0);
if (type == int.class || type == Integer.class) return Integer.valueOf(0);
if (type == float.class || type == Float.class) return Float.valueOf(0f);
if (type == long.class || type == Long.class) return Long.valueOf(0);
if (type == double.class || type == Double.class) return Double.valueOf(0d);
if (type == byte.class || type == Byte.class) return (byte) 0;
if (type == short.class || type == Short.class) return (short) 0;
if (type == char.class || type == Character.class) return (char) 0;
if (type == int.class || type == Integer.class) return 0;
if (type == float.class || type == Float.class) return 0F;
if (type == long.class || type == Long.class) return 0L;
if (type == double.class || type == Double.class) return 0D;
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ public void run(String... args) throws Exception {
}

List<String> sorted = new ArrayList<>(sizes.keys());
Collections.sort(sorted, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return Long.compare(sizes.count(o2), sizes.count(o1));
}
});
sorted.sort((o1, o2) -> Long.compare(sizes.count(o2), sizes.count(o1)));

final int printFirst = Integer.getInteger("printFirst", 30);

Expand Down
14 changes: 2 additions & 12 deletions jol-cli/src/main/java/org/openjdk/jol/operations/ObjectShapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,10 @@ public void run(String... args) throws Exception {

for (final String arg : args) {
if (arg.endsWith(".jar")) {
cs.submit(new Callable<Multiset<String>>() {
@Override
public Multiset<String> call() throws Exception {
return processJAR(arg);
}
});
cs.submit(() -> processJAR(arg));
}
if (arg.endsWith(".dump") || arg.endsWith("hprof") || arg.endsWith("hprof.gz")) {
cs.submit(new Callable<Multiset<String>>() {
@Override
public Multiset<String> call() throws Exception {
return processHeapDump(arg);
}
});
cs.submit(() -> processHeapDump(arg));
}
}

Expand Down
9 changes: 5 additions & 4 deletions jol-core/src/main/java/org/openjdk/jol/info/ClassData.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.openjdk.jol.util.ClassUtils;
import org.openjdk.jol.vm.ContendedSupport;
Expand Down Expand Up @@ -398,16 +399,16 @@ public boolean equals(Object o) {
if (length != classData.length) {
return false;
}
if (arrayComponentKlass != null ? !arrayComponentKlass.equals(classData.arrayComponentKlass) : classData.arrayComponentKlass != null) {
if (!Objects.equals(arrayComponentKlass, classData.arrayComponentKlass)) {
return false;
}
if (arrayKlass != null ? !arrayKlass.equals(classData.arrayKlass) : classData.arrayKlass != null) {
if (!Objects.equals(arrayKlass, classData.arrayKlass)) {
return false;
}
if (classNames != null ? !classNames.equals(classData.classNames) : classData.classNames != null) {
if (!Objects.equals(classNames, classData.classNames)) {
return false;
}
if (fields != null ? !fields.equals(classData.fields) : classData.fields != null) {
if (!Objects.equals(fields, classData.fields)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public int hashCode() {

@Override
public int compareTo(FieldLayout o) {
return Long.valueOf(offset).compareTo(o.offset);
return Long.compare(offset, o.offset);
}

@Override
Expand Down
7 changes: 1 addition & 6 deletions jol-core/src/main/java/org/openjdk/jol/info/GraphLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ private void ensureProcessedHisto() {
}

synchronized (this) {
classes = new TreeSet<>(new Comparator<Class<?>>() {
@Override
public int compare(Class<?> o1, Class<?> o2) {
return o1.getName().compareTo(o2.getName());
}
});
classes = new TreeSet<>(Comparator.comparing(Class::getName));
classSizes = new Multiset<>();
classCounts = new Multiset<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private ClassLayout oldLayouter(ClassData cd) {
for (FieldAllocationType atype : FieldAllocationType.values()) {
fieldsAllocationCount.put(atype, 0);
nextOffset.put(atype, 0);
spaceOffset.put(atype, new ArrayDeque<Integer>());
spaceOffset.put(atype, new ArrayDeque<>());
}
allocationTypeSizes.put(OOP, model.sizeOf("oop"));
allocationTypeSizes.put(BYTE, model.sizeOf("byte"));
Expand Down Expand Up @@ -209,11 +209,11 @@ private ClassLayout oldLayouter(ClassData cd) {
// The packing code below relies on these counts to determine if some field
// can be squeezed into the alignment gap. Contended fields are obviously
// exempt from that.
int doubleCount = fieldsAllocationCount.get(DOUBLE) - (facContended.containsKey(DOUBLE) ? facContended.get(DOUBLE) : 0);
int wordCount = fieldsAllocationCount.get(WORD) - (facContended.containsKey(WORD) ? facContended.get(WORD) : 0);
int shortCount = fieldsAllocationCount.get(SHORT) - (facContended.containsKey(SHORT) ? facContended.get(SHORT) : 0);
int byteCount = fieldsAllocationCount.get(BYTE) - (facContended.containsKey(BYTE) ? facContended.get(BYTE) : 0);
int oopCount = fieldsAllocationCount.get(OOP) - (facContended.containsKey(OOP) ? facContended.get(OOP) : 0);
int doubleCount = fieldsAllocationCount.get(DOUBLE) - (facContended.getOrDefault(DOUBLE, 0));
int wordCount = fieldsAllocationCount.get(WORD) - (facContended.getOrDefault(WORD, 0));
int shortCount = fieldsAllocationCount.get(SHORT) - (facContended.getOrDefault(SHORT, 0));
int byteCount = fieldsAllocationCount.get(BYTE) - (facContended.getOrDefault(BYTE, 0));
int oopCount = fieldsAllocationCount.get(OOP) - (facContended.getOrDefault(OOP, 0));

int firstOopOffset = 0; // will be set for first oop field

Expand Down
8 changes: 1 addition & 7 deletions jol-core/src/main/java/org/openjdk/jol/vm/HotspotUnsafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ very dirty moves to access. Since the magic field offset code pokes (*writes*)
private Object mfoUnsafe;
private Method mfoMethod;

private final ThreadLocal<Object[]> BUFFERS = new ThreadLocal<Object[]>() {
@Override
protected Object[] initialValue() {
return new Object[1];
}
};

private final ThreadLocal<Object[]> BUFFERS = ThreadLocal.withInitial(() -> new Object[1]);

HotspotUnsafe(Unsafe u, Instrumentation inst, UniverseData saDetails) {
U = u;
Expand Down
23 changes: 9 additions & 14 deletions jol-core/src/main/java/org/openjdk/jol/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@
public class VM {

private static Unsafe tryUnsafe() {
return AccessController.doPrivileged(
new PrivilegedAction<Unsafe>() {
@Override
public Unsafe run() {
try {
Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
unsafe.setAccessible(true);
return (Unsafe) unsafe.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}
);
return AccessController.doPrivileged((PrivilegedAction<Unsafe>) () -> {
try {
Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
unsafe.setAccessible(true);
return (Unsafe) unsafe.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
});
}

private static VirtualMachine INSTANCE;
Expand Down
21 changes: 9 additions & 12 deletions jol-core/src/main/java/org/openjdk/jol/vm/sa/AttachMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ public static void main(final String[] args) {

final Object agent = hotspotAgent;
Future<?> future = Executors.newCachedThreadPool(new MyThreadFactory())
.submit(new Callable<Object>() {
@Override
public Object call() {
try {
// Attach to the caller process as Hotspot agent
attachMethod.invoke(agent, (int) request.getProcessId());
return ClassUtils.loadClass(VM_CLASSNAME).getMethod("getVM").invoke(null);
} catch (Exception t) {
throw new RuntimeException(t);
}
}
}
.submit(() -> {
try {
// Attach to the caller process as Hotspot agent
attachMethod.invoke(agent, (int) request.getProcessId());
return ClassUtils.loadClass(VM_CLASSNAME).getMethod("getVM").invoke(null);
} catch (Exception t) {
throw new RuntimeException(t);
}
}
);

Object vm = future.get(request.getTimeout(), TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,12 @@ public static void main(String[] args) throws Exception {
out.println("**** Fresh object");
out.println(layout.toPrintable());

Thread t = new Thread(new Runnable() {
@Override
public void run() {
synchronized (a) {
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) {
return;
}
Thread t = new Thread(() -> {
synchronized (a) {
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) {
// Do nothing
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ public static void main(String[] args) throws Exception {
private static void addElements(final int count, final Map<Object, Object> chm) throws InterruptedException {
ExecutorService pool = Executors.newCachedThreadPool();

Runnable task = new Runnable() {
@Override
public void run() {
for (int c = 0; c < count; c++) {
Object o = new Object();
chm.put(o, o);
}
Runnable task = () -> {
for (int c = 0; c < count; c++) {
Object o = new Object();
chm.put(o, o);
}
};

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ questions.

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jol.target>1.7</jol.target>
<jol.target>1.8</jol.target>
</properties>

</project>

0 comments on commit 153c155

Please sign in to comment.