From 153c1559cdf6b43b63ea1b0085cd09694ac82c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksey=20Shipil=C3=ABv?= Date: Tue, 18 Oct 2022 18:45:41 +0200 Subject: [PATCH] 7903352: JOL: Drop support for JDK 7 --- .github/workflows/pre-integration.yml | 2 +- .../jol/operations/ClasspathedOperation.java | 14 +++++------ .../openjdk/jol/operations/HeapDumpStats.java | 7 +----- .../openjdk/jol/operations/ObjectShapes.java | 14 ++--------- .../java/org/openjdk/jol/info/ClassData.java | 9 ++++---- .../org/openjdk/jol/info/FieldLayout.java | 2 +- .../org/openjdk/jol/info/GraphLayout.java | 7 +----- .../jol/layouters/HotSpotLayouter.java | 12 +++++----- .../org/openjdk/jol/vm/HotspotUnsafe.java | 8 +------ .../src/main/java/org/openjdk/jol/vm/VM.java | 23 ++++++++----------- .../org/openjdk/jol/vm/sa/AttachMain.java | 21 ++++++++--------- .../jol/samples/JOLSample_14_FatLocking.java | 15 +++++------- .../jol/samples/JOLSample_27_Colocation.java | 11 ++++----- pom.xml | 2 +- 14 files changed, 54 insertions(+), 93 deletions(-) diff --git a/.github/workflows/pre-integration.yml b/.github/workflows/pre-integration.yml index 493b45ee..c38c0965 100644 --- a/.github/workflows/pre-integration.yml +++ b/.github/workflows/pre-integration.yml @@ -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 }} diff --git a/jol-cli/src/main/java/org/openjdk/jol/operations/ClasspathedOperation.java b/jol-cli/src/main/java/org/openjdk/jol/operations/ClasspathedOperation.java index 86ba2459..dcd6f62c 100644 --- a/jol-cli/src/main/java/org/openjdk/jol/operations/ClasspathedOperation.java +++ b/jol-cli/src/main/java/org/openjdk/jol/operations/ClasspathedOperation.java @@ -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; } diff --git a/jol-cli/src/main/java/org/openjdk/jol/operations/HeapDumpStats.java b/jol-cli/src/main/java/org/openjdk/jol/operations/HeapDumpStats.java index 472d7fd1..69677f8c 100644 --- a/jol-cli/src/main/java/org/openjdk/jol/operations/HeapDumpStats.java +++ b/jol-cli/src/main/java/org/openjdk/jol/operations/HeapDumpStats.java @@ -78,12 +78,7 @@ public void run(String... args) throws Exception { } List sorted = new ArrayList<>(sizes.keys()); - Collections.sort(sorted, new Comparator() { - @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); diff --git a/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectShapes.java b/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectShapes.java index 1edb11d7..4a2e9917 100644 --- a/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectShapes.java +++ b/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectShapes.java @@ -64,20 +64,10 @@ public void run(String... args) throws Exception { for (final String arg : args) { if (arg.endsWith(".jar")) { - cs.submit(new Callable>() { - @Override - public Multiset 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>() { - @Override - public Multiset call() throws Exception { - return processHeapDump(arg); - } - }); + cs.submit(() -> processHeapDump(arg)); } } diff --git a/jol-core/src/main/java/org/openjdk/jol/info/ClassData.java b/jol-core/src/main/java/org/openjdk/jol/info/ClassData.java index acab18f8..e83fc432 100644 --- a/jol-core/src/main/java/org/openjdk/jol/info/ClassData.java +++ b/jol-core/src/main/java/org/openjdk/jol/info/ClassData.java @@ -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; @@ -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; } diff --git a/jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java b/jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java index 2ab2dc27..bd7cbee1 100644 --- a/jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java +++ b/jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java @@ -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 diff --git a/jol-core/src/main/java/org/openjdk/jol/info/GraphLayout.java b/jol-core/src/main/java/org/openjdk/jol/info/GraphLayout.java index ff98243e..b7e8c8ea 100644 --- a/jol-core/src/main/java/org/openjdk/jol/info/GraphLayout.java +++ b/jol-core/src/main/java/org/openjdk/jol/info/GraphLayout.java @@ -201,12 +201,7 @@ private void ensureProcessedHisto() { } synchronized (this) { - classes = new TreeSet<>(new Comparator>() { - @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<>(); diff --git a/jol-core/src/main/java/org/openjdk/jol/layouters/HotSpotLayouter.java b/jol-core/src/main/java/org/openjdk/jol/layouters/HotSpotLayouter.java index 3109fa80..39344867 100644 --- a/jol-core/src/main/java/org/openjdk/jol/layouters/HotSpotLayouter.java +++ b/jol-core/src/main/java/org/openjdk/jol/layouters/HotSpotLayouter.java @@ -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()); + spaceOffset.put(atype, new ArrayDeque<>()); } allocationTypeSizes.put(OOP, model.sizeOf("oop")); allocationTypeSizes.put(BYTE, model.sizeOf("byte")); @@ -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 diff --git a/jol-core/src/main/java/org/openjdk/jol/vm/HotspotUnsafe.java b/jol-core/src/main/java/org/openjdk/jol/vm/HotspotUnsafe.java index 6ed8c3c6..5c64c023 100644 --- a/jol-core/src/main/java/org/openjdk/jol/vm/HotspotUnsafe.java +++ b/jol-core/src/main/java/org/openjdk/jol/vm/HotspotUnsafe.java @@ -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 BUFFERS = new ThreadLocal() { - @Override - protected Object[] initialValue() { - return new Object[1]; - } - }; - + private final ThreadLocal BUFFERS = ThreadLocal.withInitial(() -> new Object[1]); HotspotUnsafe(Unsafe u, Instrumentation inst, UniverseData saDetails) { U = u; diff --git a/jol-core/src/main/java/org/openjdk/jol/vm/VM.java b/jol-core/src/main/java/org/openjdk/jol/vm/VM.java index 6b2471ee..c389010f 100644 --- a/jol-core/src/main/java/org/openjdk/jol/vm/VM.java +++ b/jol-core/src/main/java/org/openjdk/jol/vm/VM.java @@ -36,20 +36,15 @@ public class VM { private static Unsafe tryUnsafe() { - return AccessController.doPrivileged( - new PrivilegedAction() { - @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) () -> { + 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; diff --git a/jol-core/src/main/java/org/openjdk/jol/vm/sa/AttachMain.java b/jol-core/src/main/java/org/openjdk/jol/vm/sa/AttachMain.java index 9b63269c..8ad32f43 100644 --- a/jol-core/src/main/java/org/openjdk/jol/vm/sa/AttachMain.java +++ b/jol-core/src/main/java/org/openjdk/jol/vm/sa/AttachMain.java @@ -66,18 +66,15 @@ public static void main(final String[] args) { final Object agent = hotspotAgent; Future future = Executors.newCachedThreadPool(new MyThreadFactory()) - .submit(new Callable() { - @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); diff --git a/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_14_FatLocking.java b/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_14_FatLocking.java index 5b47bee9..528781f0 100644 --- a/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_14_FatLocking.java +++ b/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_14_FatLocking.java @@ -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 } } }); diff --git a/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_27_Colocation.java b/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_27_Colocation.java index d930c1c9..463f423c 100644 --- a/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_27_Colocation.java +++ b/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_27_Colocation.java @@ -97,13 +97,10 @@ public static void main(String[] args) throws Exception { private static void addElements(final int count, final Map 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); } }; diff --git a/pom.xml b/pom.xml index 8da6a875..8e351312 100644 --- a/pom.xml +++ b/pom.xml @@ -128,7 +128,7 @@ questions. UTF-8 - 1.7 + 1.8