├── .gitignore
├── jol-core
├── src
│ ├── test
│ │ └── java
│ │ │ └── org
│ │ │ └── openjdk
│ │ │ └── jol
│ │ │ ├── ljv
│ │ │ ├── approvals
│ │ │ │ ├── LJVTest.testNull.approved.txt
│ │ │ │ ├── LJVTest.testMultiNull.approved.txt
│ │ │ │ ├── LJVTest.testEmptyArray.approved.txt
│ │ │ │ ├── LJVTest.testMixedNullsAndNotNulls.approved.txt
│ │ │ │ ├── LJVTest.arrayItemLinksToArray.approved.txt
│ │ │ │ ├── LJVTest.stringIsNotAPrimitiveType.approved.txt
│ │ │ │ ├── LJVTest.arrayWithFieldAttribute.approved.txt
│ │ │ │ ├── LJVTest.twoObjectsLinksToOneArray.approved.txt
│ │ │ │ ├── LJVTest.testArrayWithHighlighting.approved.txt
│ │ │ │ ├── LJVTest.objectArraysHoldReferencesPrimitiveArraysHoldValues.approved.txt
│ │ │ │ ├── LJVTest.stringIntern.approved.txt
│ │ │ │ ├── LJVTest.assignmentDoesNotCreateANewObject.approved.txt
│ │ │ │ ├── LJVTest.cyclicalStructuresClassesWithAndWithoutAToStringAndWithoutContext.approved.txt
│ │ │ │ ├── LJVTest.assignmentWithNewCreateANewObject.approved.txt
│ │ │ │ ├── LJVTest.linkedList.approved.txt
│ │ │ │ ├── LJVTest.multiDimensionalArrays.approved.txt
│ │ │ │ ├── LJVTest.reversedMultiDimensionalArrays.approved.txt
│ │ │ │ ├── LJVTest.testNewObjectsHighlighting.approved.txt
│ │ │ │ ├── LJVTest.paulsExample.approved.txt
│ │ │ │ ├── LJVTest.multipleRoots.approved.txt
│ │ │ │ ├── LJVTest.wrappedObjects.approved.txt
│ │ │ │ └── LJVTest.hashMap.approved.txt
│ │ │ ├── ArrayItem.java
│ │ │ ├── PackageSettings.java
│ │ │ ├── ObjectsWithArray.java
│ │ │ ├── Example.java
│ │ │ ├── Node.java
│ │ │ ├── VersionGuardedTest.java
│ │ │ ├── Person.java
│ │ │ ├── provider
│ │ │ │ └── impl
│ │ │ │ │ ├── NewObjectHighlighterTest.java
│ │ │ │ │ └── ChangingArrayElementHighlighterTest.java
│ │ │ └── HashCodeCollision.java
│ │ │ ├── info
│ │ │ ├── GraphLayoutExhaustionTests.java
│ │ │ ├── GraphLayoutMultipleRootTest.java
│ │ │ ├── ClassLayoutPrivatesTest.java
│ │ │ ├── GraphLayoutConstructorTest.java
│ │ │ ├── GraphLayoutImageTests.java
│ │ │ ├── ClassLayoutNamesTest.java
│ │ │ ├── GraphLayoutNamesTest.java
│ │ │ ├── ClassLayoutArraysTest.java
│ │ │ └── ClassLayoutInstanceTest.java
│ │ │ ├── util
│ │ │ ├── SimpleQueueTest.java
│ │ │ └── ByteClassLoader.java
│ │ │ ├── jvms
│ │ │ └── AnonymousTest.java
│ │ │ ├── vm
│ │ │ ├── HotspotUnsafeTest.java
│ │ │ └── ZGCAddressTest.java
│ │ │ └── layouters
│ │ │ └── HotspotLayouterRealTest.java
│ └── main
│ │ ├── resources
│ │ └── THIRD-PARTY
│ │ └── java
│ │ └── org
│ │ └── openjdk
│ │ └── jol
│ │ ├── ljv
│ │ ├── provider
│ │ │ ├── NodeTypeProvider.java
│ │ │ ├── ArrayElementAttributeProvider.java
│ │ │ ├── ObjectAttributesProvider.java
│ │ │ ├── FieldAttributesProvider.java
│ │ │ ├── NodeType.java
│ │ │ └── impl
│ │ │ │ ├── NewObjectHighlighter.java
│ │ │ │ ├── FixedValueClassAttributes.java
│ │ │ │ ├── FixedFieldAttributesProvider.java
│ │ │ │ └── FixedFieldNameAttributesProvider.java
│ │ ├── nodes
│ │ │ ├── NullNode.java
│ │ │ ├── PrimitiveNode.java
│ │ │ └── Node.java
│ │ ├── Direction.java
│ │ ├── Introspection.java
│ │ ├── Visualization.java
│ │ └── Quote.java
│ │ ├── heap
│ │ └── HeapDumpException.java
│ │ ├── vm
│ │ ├── sa
│ │ │ ├── SASupportException.java
│ │ │ ├── Response.java
│ │ │ ├── Result.java
│ │ │ ├── Constants.java
│ │ │ ├── Request.java
│ │ │ ├── SenseAccessMain.java
│ │ │ └── Task.java
│ │ ├── InstrumentationException.java
│ │ ├── ZGCAddress.java
│ │ └── Experiments.java
│ │ ├── info
│ │ ├── GraphVisitor.java
│ │ ├── FieldGraphPathRecord.java
│ │ ├── ArrayGraphPathRecord.java
│ │ ├── GraphStats.java
│ │ └── GraphPathRecord.java
│ │ ├── layouters
│ │ ├── Layouter.java
│ │ └── FieldAllocationType.java
│ │ ├── util
│ │ ├── SimpleStack.java
│ │ ├── Multimap.java
│ │ └── IOUtils.java
│ │ └── datamodel
│ │ └── DataModel.java
└── THIRD-PARTY
├── .github
└── workflows
│ └── pre-integration.yml
├── src
└── license
│ ├── gpl_cpe
│ └── header.txt
│ └── bsd
│ ├── header.txt
│ └── license.txt
├── THIRD-PARTY
├── jol-cli
├── THIRD-PARTY
└── src
│ └── main
│ ├── resources
│ └── THIRD-PARTY
│ └── java
│ └── org
│ └── openjdk
│ └── jol
│ ├── Operation.java
│ └── operations
│ ├── EstimatedModels.java
│ ├── ObjectInternals.java
│ ├── ObjectExternals.java
│ └── ObjectFootprint.java
├── jol-samples
├── THIRD-PARTY
└── src
│ ├── resources
│ ├── THIRD-PARTY
│ └── LICENSE
│ └── main
│ └── java
│ ├── org
│ └── openjdk
│ │ └── jol
│ │ ├── Sample.java
│ │ └── samples
│ │ ├── JOLSample_01_Basic.java
│ │ ├── JOLSample_17_ArrayLength.java
│ │ ├── JOLSample_02_Alignment.java
│ │ ├── JOLSample_08_Class.java
│ │ ├── JOLSample_11_ClassWord.java
│ │ ├── JOLSample_04_Inheritance.java
│ │ ├── JOLSample_06_HierarchyGaps.java
│ │ ├── JOLSample_07_Exceptions.java
│ │ └── JOLSample_15_IdentityHashCode.java
│ ├── sun
│ └── misc
│ │ └── Contended.java
│ └── jdk
│ └── internal
│ └── vm
│ └── annotation
│ └── Contended.java
├── .jcheck
└── conf
└── jol-benchmarks
└── src
└── main
└── java
└── org
└── openjdk
└── jol
├── LinkedChainBench.java
└── GraphInstanceBench.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | *.iml
3 | target/
4 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.testNull.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | NULL[label="null", shape=plaintext];
5 | }
6 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.testMultiNull.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | NULL[label="null", shape=plaintext];
5 | }
6 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.testEmptyArray.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
10 | >];
11 | }
12 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.testMixedNullsAndNotNulls.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | NULL[label="null", shape=plaintext];
5 | n1[label=<
6 |
11 | >];
12 | n2[label=<
13 |
14 |
15 | Object
16 |
17 |
18 | >];
19 | }
20 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/GraphLayoutExhaustionTests.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.LinkedList;
6 |
7 | public class GraphLayoutExhaustionTests {
8 |
9 | @Test
10 | public void testLinkedList() throws Exception {
11 | LinkedList list = new LinkedList<>();
12 | for (int i = 0; i < 1000000; i++) {
13 | list.add(i);
14 | }
15 | System.out.println(GraphLayout.parseInstance(list).toFootprint());
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.arrayItemLinksToArray.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | ArrayItem[]
8 |
9 |
10 |
11 | >];
12 | n2[label=<
13 |
14 |
15 | ArrayItem
16 |
17 |
18 | >];
19 | n2 -> n1[label="prev",fontsize=12];
20 | n1:f0 -> n2[label="0",fontsize=12];
21 | }
22 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.stringIsNotAPrimitiveType.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | String
8 |
9 |
10 | hash: 0
11 |
12 |
13 | >];
14 | n2[label=<
15 |
16 |
17 | char[]
18 | H
19 | e
20 | l
21 | l
22 | o
23 |
24 |
25 | >];
26 | n1 -> n2[label="value",fontsize=12];
27 | }
28 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.arrayWithFieldAttribute.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | String
8 |
9 |
10 | hash: 0
11 |
12 |
13 | >];
14 | n2[label=<
15 |
16 |
17 | char[]
18 | H
19 | e
20 | l
21 | l
22 | o
23 |
24 |
25 | >];
26 | n1 -> n2[label="value",fontsize=12,color=red,fontcolor=red];
27 | }
28 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.twoObjectsLinksToOneArray.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
10 | >];
11 | n2[label=<
12 |
13 |
14 | int[]
15 | 1
16 | 2
17 | 3
18 |
19 |
20 | >];
21 | n1 -> n2[label="a",fontsize=12,color=blue,fontcolor=red];
22 | n3[label=<
23 |
28 | >];
29 | n3 -> n2[label="b",fontsize=12,color=yellow,fontcolor=green];
30 | }
31 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/GraphLayoutMultipleRootTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | public class GraphLayoutMultipleRootTest {
7 |
8 | @Test
9 | public void test() {
10 | Object r = new Object();
11 | GraphLayout gl1 = GraphLayout.parseInstance(r);
12 | GraphLayout gl2 = GraphLayout.parseInstance(r, r);
13 | GraphLayout gl3 = GraphLayout.parseInstance(r, r, r);
14 |
15 | Assert.assertEquals(gl1.totalCount(), gl2.totalCount());
16 | Assert.assertEquals(gl1.totalCount(), gl3.totalCount());
17 | Assert.assertEquals(gl1.totalSize(), gl2.totalSize());
18 | Assert.assertEquals(gl1.totalSize(), gl3.totalSize());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.testArrayWithHighlighting.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | ArrayDeque
8 |
9 |
10 | head: 2
11 |
12 |
13 | tail: 3
14 |
15 |
16 | >];
17 | n2[label=<
18 |
19 |
20 | Object[]
21 | null
22 | null
23 | 3
24 | null
25 | null
26 | null
27 | null
28 | null
29 |
30 |
31 | >];
32 | n1 -> n2[label="elements",fontsize=12];
33 | }
34 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/ClassLayoutPrivatesTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Test;
4 |
5 | public class ClassLayoutPrivatesTest {
6 |
7 | static class A {
8 |
9 | }
10 |
11 | static class B {
12 | private A a = new A();
13 | }
14 |
15 | @Test
16 | public void testPrint() {
17 | ClassLayout.parseInstance(new A()).toPrintable();
18 | ClassLayout.parseInstance(new B()).toPrintable();
19 |
20 | ClassLayout.parseClass(A.class).toPrintable();
21 | ClassLayout.parseClass(B.class).toPrintable();
22 |
23 | ClassLayout.parseClass(A.class).toPrintable(new A());
24 | ClassLayout.parseClass(B.class).toPrintable(new B());
25 | }
26 |
27 | @Test
28 | public void testClass() {
29 | GraphLayout.parseInstance(this.getClass()).toPrintable();
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.objectArraysHoldReferencesPrimitiveArraysHoldValues.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | Object[]
8 |
9 |
10 |
11 |
12 | >];
13 | n2[label=<
14 |
15 |
16 | String[]
17 | a
18 | b
19 | c
20 |
21 |
22 | >];
23 | n1:f0 -> n2[label="0",fontsize=12];
24 | n3[label=<
25 |
26 |
27 | int[]
28 | 1
29 | 2
30 | 3
31 |
32 |
33 | >];
34 | n1:f1 -> n3[label="1",fontsize=12];
35 | }
36 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.stringIntern.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | Object[]
8 |
9 |
10 |
11 |
12 | >];
13 | n2[label=<
14 |
15 |
16 | String
17 |
18 |
19 | hash: 0
20 |
21 |
22 | >];
23 | n3[label=<
24 |
25 |
26 | char[]
27 | H
28 | e
29 | l
30 | l
31 | o
32 |
33 |
34 | >];
35 | n2 -> n3[label="value",fontsize=12];
36 | n1:f0 -> n2[label="0",fontsize=12];
37 | n1:f1 -> n2[label="1",fontsize=12];
38 | }
39 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.assignmentDoesNotCreateANewObject.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | Object[]
8 |
9 |
10 |
11 |
12 | >];
13 | n2[label=<
14 |
15 |
16 | String
17 |
18 |
19 | hash: 0
20 |
21 |
22 | >];
23 | n3[label=<
24 |
25 |
26 | char[]
27 | H
28 | e
29 | l
30 | l
31 | o
32 |
33 |
34 | >];
35 | n2 -> n3[label="value",fontsize=12];
36 | n1:f0 -> n2[label="0",fontsize=12];
37 | n1:f1 -> n2[label="1",fontsize=12];
38 | }
39 |
--------------------------------------------------------------------------------
/.github/workflows/pre-integration.yml:
--------------------------------------------------------------------------------
1 | name: JOL Pre-Integration Tests
2 |
3 | on:
4 | push:
5 | branches-ignore:
6 | - master
7 | - pr/*
8 | workflow_dispatch:
9 |
10 | concurrency:
11 | group: ${{ github.workflow }}-${{ github.ref }}
12 | cancel-in-progress: true
13 |
14 | jobs:
15 | test:
16 | runs-on: ${{ matrix.os }}
17 | strategy:
18 | matrix:
19 | java: [8, 11, 17, 21]
20 | os: [ubuntu-latest, windows-latest, macos-latest]
21 | fail-fast: false
22 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}
23 |
24 | steps:
25 | - uses: actions/checkout@v4
26 | - name: Set up JDK ${{ matrix.java }}
27 | uses: actions/setup-java@v4
28 | with:
29 | distribution: corretto
30 | java-version: ${{ matrix.java }}
31 | cache: maven
32 | check-latest: true
33 | - name: Build all without tests
34 | run: mvn clean install -DskipTests -B --file pom.xml
35 | - name: Run tests
36 | run: mvn test -B --file pom.xml
37 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.cyclicalStructuresClassesWithAndWithoutAToStringAndWithoutContext.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | Node
8 |
9 |
10 | A
11 |
12 |
13 | >,color=pink,style=filled];
14 | n2[label=<
15 |
16 |
17 | AnotherNode
18 |
19 |
20 | B
21 |
22 |
23 | null
24 |
25 |
26 | null
27 |
28 |
29 | >];
30 | n1 -> n2[label="left",fontsize=12,color=red,fontcolor=red];
31 | n3[label=<
32 |
33 |
34 | AnotherNode
35 |
36 |
37 | C
38 |
39 |
40 | >];
41 | n3 -> n1[label="left",fontsize=12,color=red,fontcolor=red];
42 | n3 -> n1[label="right",fontsize=12,color=blue,fontcolor=blue];
43 | n1 -> n3[label="right",fontsize=12,color=blue,fontcolor=blue];
44 | }
45 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.assignmentWithNewCreateANewObject.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | Object[]
8 |
9 |
10 |
11 |
12 | >];
13 | n2[label=<
14 |
15 |
16 | String
17 |
18 |
19 | hash: 0
20 |
21 |
22 | >];
23 | n3[label=<
24 |
25 |
26 | char[]
27 | H
28 | e
29 | l
30 | l
31 | o
32 |
33 |
34 | >];
35 | n2 -> n3[label="value",fontsize=12];
36 | n1:f0 -> n2[label="0",fontsize=12];
37 | n4[label=<
38 |
39 |
40 | String
41 |
42 |
43 | hash: 0
44 |
45 |
46 | >];
47 | n4 -> n3[label="value",fontsize=12];
48 | n1:f1 -> n4[label="1",fontsize=12];
49 | }
50 |
--------------------------------------------------------------------------------
/src/license/gpl_cpe/header.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2 | DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 |
4 | This code is free software; you can redistribute it and/or modify it
5 | under the terms of the GNU General Public License version 2 only, as
6 | published by the Free Software Foundation. Oracle designates this
7 | particular file as subject to the "Classpath" exception as provided
8 | by Oracle in the LICENSE file that accompanied this code.
9 |
10 | This code is distributed in the hope that it will be useful, but WITHOUT
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 | version 2 for more details (a copy is included in the LICENSE file that
14 | accompanied this code).
15 |
16 | You should have received a copy of the GNU General Public License version
17 | 2 along with this work; if not, write to the Free Software Foundation,
18 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 |
20 | Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 | or visit www.oracle.com if you need additional information or have any
22 | questions.
23 |
--------------------------------------------------------------------------------
/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-cli/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-core/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-samples/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-cli/src/main/resources/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-core/src/main/resources/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-samples/src/resources/THIRD-PARTY:
--------------------------------------------------------------------------------
1 | DO NOT TRANSLATE OR LOCALIZE.
2 | -----------------------------
3 |
4 | %% This notice is provided with respect to JOpt-Simple v4.6
5 |
6 | --- begin of LICENSE ---
7 |
8 | Copyright (c) SourceForge
9 |
10 | The MIT License Copyright (c) Permission is hereby granted, free of
11 | charge, to any person obtaining a copy of this software and associated
12 | documentation files (the "Software"), to deal in the Software without
13 | restriction, including without limitation the rights to use, copy,
14 | modify, merge, publish, distribute, sublicense, and/or sell copies of
15 | the Software, and to permit persons to whom the Software is furnished
16 | to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included
19 | in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | --- end of LICENSE ---
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/GraphLayoutConstructorTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | public class GraphLayoutConstructorTest {
7 |
8 | static class A {
9 |
10 | }
11 |
12 | @Test
13 | public void varargs() {
14 | Assert.assertEquals("Reports one A",
15 | 1, GraphLayout.parseInstance(new A()).totalCount());
16 |
17 | Assert.assertEquals("Reports two A",
18 | 2, GraphLayout.parseInstance(new A(), new A()).totalCount());
19 |
20 | Assert.assertEquals("Reports single A", // varargs unfolds
21 | 1, GraphLayout.parseInstance(new A[]{ new A() }).totalCount());
22 |
23 | Assert.assertEquals("Reports array and A", // explicitly avoiding varargs
24 | 2, GraphLayout.parseInstance((Object)new A[]{ new A() }).totalCount());
25 |
26 | Assert.assertEquals("Reports one array and two A-s",
27 | 3, GraphLayout.parseInstance(new A[]{ new A() }, new A()).totalCount());
28 |
29 | Assert.assertEquals("Reports two arrays and one A",
30 | 3, GraphLayout.parseInstance(new A[]{ new A() }, new A[]{ }).totalCount());
31 |
32 | Assert.assertEquals("Reports two arrays and two A-s",
33 | 4, GraphLayout.parseInstance(new A[]{ new A() }, new A[]{ new A() }).totalCount());
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/ArrayItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | public class ArrayItem {
28 | public ArrayItem[] prev;
29 | }
30 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/PackageSettings.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | public class PackageSettings {
28 | public static final String UseApprovalSubdirectory = "approvals";
29 | }
30 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/NodeTypeProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider;
26 |
27 | public interface NodeTypeProvider {
28 | NodeType getNodeType(Object object, Object parentObject);
29 | }
30 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/ArrayElementAttributeProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider;
26 |
27 | public interface ArrayElementAttributeProvider {
28 | String getAttribute(Object array, int index);
29 | }
30 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/heap/HeapDumpException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2014, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.heap;
26 |
27 | public class HeapDumpException extends Exception {
28 | public HeapDumpException(String s) {
29 | super(s);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/jol-cli/src/main/java/org/openjdk/jol/Operation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol;
26 |
27 | public interface Operation {
28 |
29 | String label();
30 |
31 | String description();
32 |
33 | void run(String... args) throws Exception;
34 | }
35 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.linkedList.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | LinkedList
8 |
9 |
10 | modCount: 3
11 |
12 |
13 | size: 3
14 |
15 |
16 | >];
17 | n2[label=<
18 |
19 |
20 | Node
21 |
22 |
23 | item: 1
24 |
25 |
26 | prev: null
27 |
28 |
29 | >];
30 | n3[label=<
31 |
32 |
33 | Node
34 |
35 |
36 | item: 42
37 |
38 |
39 | >];
40 | n4[label=<
41 |
42 |
43 | Node
44 |
45 |
46 | item: 21
47 |
48 |
49 | next: null
50 |
51 |
52 | >];
53 | n4 -> n3[label="prev",fontsize=12,color=blue,fontcolor=blue];
54 | n3 -> n4[label="next",fontsize=12,color=red,fontcolor=red];
55 | n3 -> n2[label="prev",fontsize=12,color=blue,fontcolor=blue];
56 | n2 -> n3[label="next",fontsize=12,color=red,fontcolor=red];
57 | n1 -> n2[label="first",fontsize=12,color=red,fontcolor=red];
58 | n1 -> n4[label="last",fontsize=12,color=red,fontcolor=red];
59 | }
60 |
--------------------------------------------------------------------------------
/.jcheck/conf:
--------------------------------------------------------------------------------
1 | ;
2 | ; Copyright (c) 2020, 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 | [general]
25 | project=code-tools
26 | repository=jol
27 | jbs=codetools
28 |
29 | [checks]
30 | error=author,committer,reviewers,executable,symlink,whitespace
31 |
32 | [census]
33 | version=0
34 | domain=openjdk.org
35 |
36 | [checks "whitespace"]
37 | files=.*\.cpp|.*\.hpp|.*\.c|.*\.h|.*\.java|.*\.cc|.*\.hh|.*\.m|.*\.mm
38 |
39 | [checks "reviewers"]
40 | committers=1
41 | ignore=duke
42 |
43 | [checks "committer"]
44 | role=committer
45 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.multiDimensionalArrays.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | int[][]
8 |
9 |
10 |
11 |
12 |
13 |
14 | >];
15 | n2[label=<
16 |
17 |
18 | int[]
19 | 0
20 | 0
21 | 0
22 | 0
23 | 0
24 |
25 |
26 | >];
27 | n1:f0 -> n2[label="0",fontsize=12];
28 | n3[label=<
29 |
30 |
31 | int[]
32 | 0
33 | 0
34 | 0
35 | 0
36 | 0
37 |
38 |
39 | >];
40 | n1:f1 -> n3[label="1",fontsize=12];
41 | n4[label=<
42 |
43 |
44 | int[]
45 | 0
46 | 0
47 | 0
48 | 0
49 | 0
50 |
51 |
52 | >];
53 | n1:f2 -> n4[label="2",fontsize=12];
54 | n5[label=<
55 |
56 |
57 | int[]
58 | 0
59 | 0
60 | 0
61 | 0
62 | 0
63 |
64 |
65 | >];
66 | n1:f3 -> n5[label="3",fontsize=12];
67 | }
68 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.reversedMultiDimensionalArrays.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="LR";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | int[][]
8 |
9 |
10 |
11 |
12 |
13 |
14 | >];
15 | n2[label=<
16 |
17 |
18 | int[]
19 | 0
20 | 0
21 | 0
22 | 0
23 | 0
24 |
25 |
26 | >];
27 | n1:f0 -> n2[label="0",fontsize=12];
28 | n3[label=<
29 |
30 |
31 | int[]
32 | 0
33 | 0
34 | 0
35 | 0
36 | 0
37 |
38 |
39 | >];
40 | n1:f1 -> n3[label="1",fontsize=12];
41 | n4[label=<
42 |
43 |
44 | int[]
45 | 0
46 | 0
47 | 0
48 | 0
49 | 0
50 |
51 |
52 | >];
53 | n1:f2 -> n4[label="2",fontsize=12];
54 | n5[label=<
55 |
56 |
57 | int[]
58 | 0
59 | 0
60 | 0
61 | 0
62 | 0
63 |
64 |
65 | >];
66 | n1:f3 -> n5[label="3",fontsize=12];
67 | }
68 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/ObjectsWithArray.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | class A {
28 | public A(int[] a) {
29 | this.a = a;
30 | }
31 |
32 | int[] a;
33 | }
34 |
35 | class B {
36 | public B(int[] b) {
37 | this.b = b;
38 | }
39 |
40 | int[] b;
41 | }
42 |
--------------------------------------------------------------------------------
/src/license/bsd/header.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, Oracle America, Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of Oracle nor the names of its contributors may be used
15 | to endorse or promote products derived from this software without
16 | specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/src/license/bsd/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Oracle America, Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of Oracle nor the names of its contributors may be used
15 | to endorse or promote products derived from this software without
16 | specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/jol-samples/src/resources/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Oracle America, Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of Oracle nor the names of its contributors may be used
15 | to endorse or promote products derived from this software without
16 | specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/SASupportException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | @SuppressWarnings("serial")
28 | class SASupportException extends RuntimeException {
29 | SASupportException(String msg, Throwable exc) {
30 | super(msg, exc);
31 | }
32 |
33 | SASupportException(String msg) {
34 | super(msg);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/Example.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | public class Example {
28 | private Integer i1 = 42;
29 | private Integer i2 = 42;
30 | private Integer i3 = 2020;
31 | private Integer i4 = 2020;
32 | private String s1 = "HelloWorld";
33 | private String s2 = "HELL O";
34 | private String s3 = "HelloWorld";
35 | }
36 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/info/GraphVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.info;
26 |
27 | /**
28 | * Object graph visitor callback.
29 | *
30 | * @author Aleksey Shipilev
31 | */
32 | public interface GraphVisitor {
33 |
34 | /**
35 | * Visit the graph record
36 | *
37 | * @param gpr path record
38 | */
39 | void visit(GraphPathRecord gpr);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/InstrumentationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm;
26 |
27 | @SuppressWarnings("serial")
28 | class InstrumentationException extends RuntimeException {
29 | InstrumentationException(String msg, Throwable exc) {
30 | super(msg, exc);
31 | }
32 |
33 | InstrumentationException(String msg) {
34 | super(msg);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/nodes/NullNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.nodes;
26 |
27 | import org.openjdk.jol.ljv.Visualization;
28 |
29 | public class NullNode extends Node {
30 |
31 | public NullNode(Object obj, String name) {
32 | super(obj, name);
33 | }
34 |
35 | @Override
36 | public void visit(Visualization v) {
37 | v.visitNull();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/layouters/Layouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.layouters;
26 |
27 | import org.openjdk.jol.info.ClassData;
28 | import org.openjdk.jol.info.ClassLayout;
29 |
30 | /**
31 | * Layouter: given the class data, produces the layout.
32 | *
33 | * @author Aleksey Shipilev
34 | */
35 | public interface Layouter {
36 |
37 | ClassLayout layout(ClassData data);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/ObjectAttributesProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider;
26 |
27 | /**
28 | * Provides DOT attributes (color, font etc.) for a given object.
29 | */
30 | public interface ObjectAttributesProvider {
31 | /**
32 | * Get map of attributes.
33 | *
34 | * @param o Object
35 | * @return Map of attribute values
36 | */
37 | String getAttribute(Object o);
38 | }
39 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/nodes/PrimitiveNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.nodes;
26 |
27 | import org.openjdk.jol.ljv.Visualization;
28 |
29 | public class PrimitiveNode extends Node {
30 |
31 | public PrimitiveNode(Object obj, String name) {
32 | super(obj, name);
33 | }
34 |
35 | @Override
36 | public void visit(Visualization v) {
37 | v.visitObjectPrimitiveField(getName(), String.valueOf(getValue()));
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.testNewObjectsHighlighting.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | TreeMap
8 |
9 |
10 | size: 4
11 |
12 |
13 | modCount: 4
14 |
15 |
16 | >];
17 | n2[label=<
18 |
19 |
20 | Entry
21 |
22 |
23 | key: three
24 |
25 |
26 | value: 3
27 |
28 |
29 | >];
30 | n3[label=<
31 |
32 |
33 | Entry
34 |
35 |
36 | key: one
37 |
38 |
39 | value: 1
40 |
41 |
42 | >];
43 | n4[label=<
44 |
45 |
46 | Entry
47 |
48 |
49 | key: four
50 |
51 |
52 | value: 4
53 |
54 |
55 | >,style=filled,fillcolor=yellow];
56 | n4 -> n3[label="parent",fontsize=12];
57 | n3 -> n4[label="left",fontsize=12];
58 | n3 -> n2[label="parent",fontsize=12];
59 | n2 -> n3[label="left",fontsize=12];
60 | n5[label=<
61 |
62 |
63 | Entry
64 |
65 |
66 | key: two
67 |
68 |
69 | value: 2
70 |
71 |
72 | >];
73 | n5 -> n2[label="parent",fontsize=12];
74 | n2 -> n5[label="right",fontsize=12];
75 | n1 -> n2[label="root",fontsize=12];
76 | }
77 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/util/SimpleQueueTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.util;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | public class SimpleQueueTest {
7 |
8 | @Test
9 | public void testSingle() {
10 | SimpleStack q = new SimpleStack<>();
11 |
12 | Object o1 = new Object();
13 |
14 | Assert.assertTrue(q.isEmpty());
15 | q.push(o1);
16 | Assert.assertFalse(q.isEmpty());
17 | Object r1 = q.pop();
18 | Assert.assertEquals(o1, r1);
19 | Assert.assertTrue(q.isEmpty());
20 | }
21 |
22 | @Test
23 | public void testOrder() {
24 | SimpleStack q = new SimpleStack<>();
25 |
26 | Object o1 = new Object();
27 | Object o2 = new Object();
28 |
29 | Assert.assertTrue(q.isEmpty());
30 | q.push(o1);
31 | q.push(o2);
32 | Assert.assertFalse(q.isEmpty());
33 | Object r2 = q.pop();
34 | Object r1 = q.pop();
35 | Assert.assertEquals(o1, r1);
36 | Assert.assertEquals(o2, r2);
37 | Assert.assertTrue(q.isEmpty());
38 | }
39 |
40 | @Test
41 | public void testGrow() {
42 | SimpleStack q = new SimpleStack<>();
43 |
44 | Object o1 = new Object();
45 | Object o2 = new Object();
46 | Object o3 = new Object();
47 |
48 | Assert.assertTrue(q.isEmpty());
49 | q.push(o1);
50 | q.push(o2);
51 | q.push(o3);
52 | Assert.assertFalse(q.isEmpty());
53 | Object r3 = q.pop();
54 | Object r2 = q.pop();
55 | Object r1 = q.pop();
56 | Assert.assertEquals(o1, r1);
57 | Assert.assertEquals(o2, r2);
58 | Assert.assertEquals(o3, r3);
59 | Assert.assertTrue(q.isEmpty());
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/FieldAttributesProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider;
26 |
27 | import java.lang.reflect.Field;
28 |
29 | /**
30 | * Provides DOT attributes (color, font etc.) for a given field.
31 | */
32 | public interface FieldAttributesProvider {
33 | /**
34 | * Get map of attributes.
35 | *
36 | * @param field Field information
37 | * @param val Field value
38 | * @return Map of attribute values
39 | */
40 | String getAttribute(Field field, Object val);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/Direction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | /**
28 | * Represents direction of graph layout. Corresponds to possible values of rankdir command in Graphviz.
29 | */
30 | public enum Direction {
31 | /**
32 | * draws from bottom to top
33 | */
34 | BT,
35 | /**
36 | * draws from left to right
37 | */
38 | LR,
39 | /**
40 | * draws from top to bottom (the default value)
41 | */
42 | TB,
43 | /**
44 | * draws from right to left
45 | */
46 | RL
47 | }
48 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/Node.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | class Node {
28 | String name;
29 | int level;
30 | AnotherNode left, right;
31 |
32 | public Node(String n) {
33 | name = n;
34 | }
35 |
36 | public String toString() {
37 | return "";
38 | }
39 | }
40 |
41 | class AnotherNode {
42 | String name;
43 | int level;
44 | Node left, right;
45 |
46 | public AnotherNode(String n) {
47 | name = n;
48 | }
49 |
50 | public String toString() {
51 | return "";
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/NodeType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider;
26 |
27 | public enum NodeType {
28 | /**
29 | * Array node.
30 | */
31 | ARRAY,
32 | /**
33 | * Non-primitive object. If a value of a field, then it is represented as an arrow.
34 | */
35 | REFERENCE,
36 | /**
37 | * Primitive field of an object.
38 | */
39 | PRIMITIVE,
40 | /**
41 | * Null reference. We always draw it as a separate node, we do not deduplicate nulls.
42 | */
43 | NULL_REFERENCE,
44 | /**
45 | * Hidden node.
46 | */
47 | IGNORE
48 | }
49 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/Sample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, Red Hat, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol;
32 |
33 | /**
34 | * This class is here to generate Javadoc for jol-samples, which otherwise
35 | * would not be able to promote to Maven Central.
36 | */
37 | public class Sample {
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.paulsExample.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | ArrayList
8 |
9 |
10 | modCount: 3
11 |
12 |
13 | size: 3
14 |
15 |
16 | >];
17 | n2[label=<
18 |
19 |
20 | Object[]
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | >];
34 | n3[label=<
35 |
36 |
37 | Person
38 |
39 |
40 | age: 35
41 |
42 |
43 | name: Albert
44 |
45 |
46 | gender: MALE
47 |
48 |
49 | >];
50 | n2:f0 -> n3[label="0",fontsize=12];
51 | n4[label=<
52 |
53 |
54 | Person
55 |
56 |
57 | age: 20
58 |
59 |
60 | name: Betty
61 |
62 |
63 | gender: FEMALE
64 |
65 |
66 | >];
67 | n2:f1 -> n4[label="1",fontsize=12];
68 | n5[label=<
69 |
70 |
71 | Point
72 |
73 |
74 | x: 100
75 |
76 |
77 | y: -100
78 |
79 |
80 | >];
81 | n2:f2 -> n5[label="2",fontsize=12];
82 | n1 -> n2[label="elementData",fontsize=12];
83 | }
84 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/info/FieldGraphPathRecord.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Red Hat Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.info;
26 |
27 | /**
28 | * Object path in object graph.
29 | *
30 | * @author Aleksey Shipilev
31 | */
32 | final class FieldGraphPathRecord extends GraphPathRecord {
33 | private final String name;
34 |
35 | FieldGraphPathRecord(GraphPathRecord parent, String name, int depth, Object obj) {
36 | super(parent, depth, obj);
37 | this.name = name;
38 | }
39 |
40 | @Override
41 | public final String path() {
42 | if (parent != null) {
43 | return parent.path() + "." + name;
44 | } else {
45 | return name;
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/info/ArrayGraphPathRecord.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Red Hat Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.info;
26 |
27 |
28 | /**
29 | * Object path in object graph.
30 | *
31 | * @author Aleksey Shipilev
32 | */
33 | final class ArrayGraphPathRecord extends GraphPathRecord {
34 | private final int idx;
35 |
36 | ArrayGraphPathRecord(GraphPathRecord parent, int idx, int depth, Object obj) {
37 | super(parent, depth, obj);
38 | this.idx = idx;
39 | }
40 |
41 | @Override
42 | public final String path() {
43 | if (parent != null) {
44 | return parent.path() + "[" + idx + "]";
45 | } else {
46 | return "[" + idx + "]";
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.multipleRoots.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | Person
8 |
9 |
10 | age: 35
11 |
12 |
13 | >];
14 | n2[label=<
15 |
16 |
17 | String
18 |
19 |
20 | hash: 0
21 |
22 |
23 | >];
24 | n3[label=<
25 |
26 |
27 | char[]
28 | A
29 | l
30 | b
31 | e
32 | r
33 | t
34 |
35 |
36 | >];
37 | n2 -> n3[label="value",fontsize=12];
38 | n1 -> n2[label="name",fontsize=12];
39 | n4[label=<
40 |
41 |
42 | Gender
43 |
44 |
45 | ordinal: 0
46 |
47 |
48 | >];
49 | n5[label=<
50 |
51 |
52 | String
53 |
54 |
55 | hash: 0
56 |
57 |
58 | >];
59 | n6[label=<
60 |
61 |
62 | char[]
63 | M
64 | A
65 | L
66 | E
67 |
68 |
69 | >];
70 | n5 -> n6[label="value",fontsize=12];
71 | n4 -> n5[label="name",fontsize=12];
72 | n1 -> n4[label="gender",fontsize=12];
73 | n7[label=<
74 |
75 |
76 | Person
77 |
78 |
79 | age: 35
80 |
81 |
82 | >];
83 | n7 -> n2[label="name",fontsize=12];
84 | n7 -> n4[label="gender",fontsize=12];
85 | }
86 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/jvms/AnonymousTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, Red Hat Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package org.openjdk.jol.jvms;
27 |
28 | import org.junit.Assert;
29 | import org.junit.Test;
30 | import org.openjdk.jol.info.ClassLayout;
31 |
32 | import java.io.IOException;
33 |
34 | public class AnonymousTest {
35 |
36 | @Test
37 | public void test() throws ClassNotFoundException, IOException {
38 | Runnable r = new Runnable() {
39 | @Override
40 | public void run() {
41 | // deliberately blank
42 | }
43 | };
44 |
45 | Assert.assertNotNull(ClassLayout.parseInstance(r).toPrintable());
46 | Assert.assertNotNull(ClassLayout.parseClass(r.getClass()).toPrintable());
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/impl/NewObjectHighlighter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider.impl;
26 |
27 | import org.openjdk.jol.ljv.provider.ObjectAttributesProvider;
28 |
29 | import java.util.IdentityHashMap;
30 | import java.util.Map;
31 |
32 | public class NewObjectHighlighter implements ObjectAttributesProvider {
33 | public static final String HIGHLIGHT = "style=filled,fillcolor=yellow";
34 |
35 | private final Map known = new IdentityHashMap<>();
36 | private final Object dummy = new Object();
37 |
38 | @Override
39 | public String getAttribute(Object o) {
40 | if (known.put(o, dummy) == null) {
41 | return HIGHLIGHT;
42 | } else {
43 | return "";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/Response.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | import java.io.Serializable;
28 |
29 | /**
30 | * Represents response from HotSpot agent process by holding result and error if occurred.
31 | */
32 | @SuppressWarnings("serial")
33 | class Response implements Serializable {
34 |
35 | private final Result result;
36 | private final Throwable error;
37 |
38 | Response(Result result) {
39 | this.result = result;
40 | this.error = null;
41 | }
42 |
43 | Response(Throwable error) {
44 | this.result = null;
45 | this.error = error;
46 | }
47 |
48 | Result getResult() {
49 | return result;
50 | }
51 |
52 | Throwable getError() {
53 | return error;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/Result.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | import java.io.Serializable;
28 |
29 | /**
30 | *
31 | * Interface for types of {@link Task#process()} return. It is designed to hold all results under a hierarchy.
32 | *
33 | *
34 | *
35 | * {@link Result} implementations must be fully (including its fields) serializable.
36 | * So if there is any field will not be serialized, it must be ignored or serialization logic must be customized.
37 | * Please see http://www.oracle.com/technetwork/articles/java/javaserial-1536170.html for more details.
38 | *
39 | *
40 | * @author Serkan Ozal
41 | */
42 | interface Result extends Serializable {
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/sun/misc/Contended.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package sun.misc;
32 |
33 | import java.lang.annotation.ElementType;
34 | import java.lang.annotation.Retention;
35 | import java.lang.annotation.RetentionPolicy;
36 | import java.lang.annotation.Target;
37 |
38 | @Target(ElementType.FIELD)
39 | @Retention(RetentionPolicy.RUNTIME)
40 | public @interface Contended {
41 | /**
42 | * Contended group
43 | */
44 | String value() default "";
45 | }
46 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/impl/FixedValueClassAttributes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider.impl;
26 |
27 | import org.openjdk.jol.ljv.provider.ObjectAttributesProvider;
28 |
29 | import java.util.Objects;
30 |
31 | public class FixedValueClassAttributes implements ObjectAttributesProvider {
32 |
33 | private final Class> aClass;
34 | private final String attributes;
35 |
36 | public FixedValueClassAttributes(Class> aClass, String values) {
37 | this.aClass = Objects.requireNonNull(aClass);
38 | this.attributes = Objects.requireNonNull(values);
39 | }
40 |
41 | @Override
42 | public String getAttribute(Object o) {
43 | if (aClass.equals(o.getClass())) {
44 | return attributes;
45 | } else {
46 | return "";
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | class Constants {
28 |
29 | static final String HOTSPOT_AGENT_CLASSNAME = "sun.jvm.hotspot.HotSpotAgent";
30 | static final String VM_CLASSNAME = "sun.jvm.hotspot.runtime.VM";
31 | static final String COMP_OOPS_CLASSNAME = "sun.jvm.hotspot.oops.CompressedOops";
32 | static final String COMP_KLASS_CLASSNAME = "sun.jvm.hotspot.oops.CompressedKlassPointers";
33 | static final String UNIVERSE_CLASSNAME = "sun.jvm.hotspot.memory.Universe";
34 |
35 | static final String SKIP_HOTSPOT_SA_ATTACH_FLAG = "jol.skipHotspotSAAttach";
36 | static final String TRY_WITH_SUDO_FLAG = "jol.tryWithSudo";
37 |
38 | static final int DEFAULT_TIMEOUT_IN_MSECS = 5000;
39 | static final int VM_CHECK_PERIOD_SENSITIVITY_IN_MSECS = 100;
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/jdk/internal/vm/annotation/Contended.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package jdk.internal.vm.annotation;
32 |
33 | import java.lang.annotation.ElementType;
34 | import java.lang.annotation.Retention;
35 | import java.lang.annotation.RetentionPolicy;
36 | import java.lang.annotation.Target;
37 |
38 | @Target(ElementType.FIELD)
39 | @Retention(RetentionPolicy.RUNTIME)
40 | public @interface Contended {
41 | /**
42 | * Contended group
43 | */
44 | String value() default "";
45 | }
46 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/Request.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | import java.io.Serializable;
28 |
29 | /**
30 | * Represents request to HotSpot agent process by holding process id, timeout and {@link Task} to execute.
31 | */
32 | @SuppressWarnings("serial")
33 | class Request implements Serializable {
34 |
35 | private final long processId;
36 | private final Task processor;
37 | private final int timeout;
38 |
39 | Request(long processId, Task processor, int timeout) {
40 | this.processId = processId;
41 | this.processor = processor;
42 | this.timeout = timeout;
43 | }
44 |
45 | long getProcessId() {
46 | return processId;
47 | }
48 |
49 | Task getProcessor() {
50 | return processor;
51 | }
52 |
53 | int getTimeout() {
54 | return timeout;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/impl/FixedFieldAttributesProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider.impl;
26 |
27 | import org.openjdk.jol.ljv.provider.FieldAttributesProvider;
28 |
29 | import java.lang.reflect.Field;
30 | import java.util.Objects;
31 |
32 | public class FixedFieldAttributesProvider implements FieldAttributesProvider {
33 | private final Field field;
34 | private final String attributes;
35 |
36 | public FixedFieldAttributesProvider(Field field, String attributes) {
37 | this.field = Objects.requireNonNull(field);
38 | this.attributes = Objects.requireNonNull(attributes);
39 | }
40 |
41 | @Override
42 | public String getAttribute(Field field, Object val) {
43 | if (this.field.equals(field)) {
44 | return attributes;
45 | } else {
46 | return "";
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/GraphLayoutImageTests.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | import java.io.File;
7 |
8 | public class GraphLayoutImageTests {
9 |
10 | @Test
11 | public void testNull() throws Exception {
12 | File file = File.createTempFile("jol", "imagetest");
13 | try {
14 | GraphLayout.parseInstance(null).toImage(file.getAbsolutePath());
15 | Assert.fail();
16 | } catch (IllegalArgumentException e) {
17 | // expected
18 | }
19 | }
20 |
21 | @Test
22 | public void testNullVararg() throws Exception {
23 | Object obj = new Object();
24 | File file = File.createTempFile("jol", "imagetest");
25 | try {
26 | GraphLayout.parseInstance(obj, null).toImage(file.getAbsolutePath());
27 | Assert.fail();
28 | } catch (IllegalArgumentException e) {
29 | // expected
30 | }
31 | }
32 |
33 | @Test
34 | public void testSingleObject() throws Exception {
35 | Object obj = new Object();
36 |
37 | File file = File.createTempFile("jol", "imagetest");
38 | GraphLayout.parseInstance(obj).toImage(file.getAbsolutePath());
39 | Assert.assertTrue(file.exists());
40 | Assert.assertTrue(file.length() > 0);
41 | }
42 |
43 | @Test
44 | public void testSingleArray() throws Exception {
45 | int[] array = new int[10];
46 |
47 | File file = File.createTempFile("jol", "imagetest");
48 | GraphLayout.parseInstance(array).toImage(file.getAbsolutePath());
49 | Assert.assertTrue(file.exists());
50 | Assert.assertTrue(file.length() > 0);
51 | }
52 |
53 | @Test
54 | public void testMultipleArrays() throws Exception {
55 | int[] arr1 = new int[10];
56 | int[] arr2 = new int[10];
57 |
58 | File file = File.createTempFile("jol", "imagetest");
59 | GraphLayout.parseInstance(arr1, arr2).toImage(file.getAbsolutePath());
60 | Assert.assertTrue(file.exists());
61 | Assert.assertTrue(file.length() > 0);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/VersionGuardedTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | public class VersionGuardedTest {
28 | int VERSION = getVersion();
29 |
30 | public boolean is8() {
31 | return VERSION == 8;
32 | }
33 |
34 | static int getVersion() {
35 | // Java 8 or lower: 1.6.0_23, 1.7.0, 1.7.0_80, 1.8.0_211
36 | // Java 9 or higher: 9.0.1, 11.0.4, 12, 12.0.1
37 | String version = "-1";
38 | String fullVersion = System.getProperty("java.version");
39 | if (fullVersion.startsWith("1.")) {
40 | version = fullVersion.substring(2, 3);
41 | } else {
42 | int dotPos = fullVersion.indexOf(".");
43 | if (dotPos != -1) {
44 | version = fullVersion.substring(0, dotPos);
45 | }
46 | }
47 | return Integer.parseInt(version);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | enum Gender {
28 | MALE,
29 | FEMALE,
30 | OTHER,
31 | }
32 |
33 | class Person {
34 | private String name;
35 | private Gender gender;
36 | private int age;
37 |
38 | public Person(String n, Gender g, int a) {
39 | setName(n);
40 | setGender(g);
41 | setAge(a);
42 | }
43 |
44 | public int getAge() {
45 | return age;
46 | }
47 |
48 | public void setAge(int age) {
49 | this.age = age;
50 | }
51 |
52 | public Gender getGender() {
53 | return gender;
54 | }
55 |
56 | public void setGender(Gender gender) {
57 | this.gender = gender;
58 | }
59 |
60 | public String getName() {
61 | return name;
62 | }
63 |
64 | public void setName(String name) {
65 | this.name = name;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/ClassLayoutNamesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Amazon.com Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package org.openjdk.jol.info;
27 |
28 | import org.junit.Assert;
29 | import org.junit.Test;
30 |
31 | public class ClassLayoutNamesTest {
32 |
33 | static class A {
34 | int[] array = new int[10];
35 | B[] bs = new B[10];
36 |
37 | class B {
38 |
39 | }
40 | }
41 |
42 | @Test
43 | public void testPrintA() {
44 | String print = ClassLayout.parseInstance(new A()).toPrintable();
45 | Assert.assertTrue(print, print.contains("int[]"));
46 | Assert.assertTrue(print, print.contains(".A.B[]"));
47 | Assert.assertTrue(print, print.contains(".A.B"));
48 | }
49 |
50 | @Test
51 | public void testPrintB() {
52 | String print = ClassLayout.parseInstance(new A().new B()).toPrintable();
53 | Assert.assertTrue(print, print.contains(".A"));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/SenseAccessMain.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | import org.openjdk.jol.util.ClassUtils;
28 |
29 | import static org.openjdk.jol.vm.sa.Constants.*;
30 |
31 | class SenseAccessMain {
32 |
33 | public static void main(final String[] args) {
34 | try {
35 | System.setProperty("sun.jvm.hotspot.debugger.useProcDebugger", "true");
36 | System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true");
37 |
38 | ClassUtils.loadClass(VM_CLASSNAME).getMethod("getVM");
39 | ClassUtils.loadClass(HOTSPOT_AGENT_CLASSNAME).newInstance();
40 | ClassUtils.loadClass(HOTSPOT_AGENT_CLASSNAME).getMethod("attach",int.class);
41 | ClassUtils.loadClass(HOTSPOT_AGENT_CLASSNAME).getMethod("detach");
42 | } catch (Throwable t) {
43 | System.exit(1);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/provider/impl/NewObjectHighlighterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider.impl;
26 |
27 | import org.junit.Assert;
28 | import org.junit.Test;
29 | import org.openjdk.jol.ljv.VersionGuardedTest;
30 |
31 | import static org.junit.Assume.assumeTrue;
32 | import static org.openjdk.jol.ljv.provider.impl.NewObjectHighlighter.HIGHLIGHT;
33 |
34 | public class NewObjectHighlighterTest extends VersionGuardedTest {
35 | @Test
36 | public void newObjectsAreHighlighted() {
37 | assumeTrue(is8());
38 | Object o1 = new Object();
39 | Object o2 = new Object();
40 | NewObjectHighlighter highlighter = new NewObjectHighlighter();
41 | Assert.assertEquals(HIGHLIGHT, highlighter.getAttribute(o1));
42 | Assert.assertEquals(HIGHLIGHT, highlighter.getAttribute(o2));
43 | Assert.assertEquals("", highlighter.getAttribute(o1));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/GraphLayoutNamesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Amazon.com Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package org.openjdk.jol.info;
27 |
28 | import org.junit.Assert;
29 | import org.junit.Test;
30 |
31 | public class GraphLayoutNamesTest {
32 |
33 | static class A {
34 | int[] array = new int[10];
35 | B[] bs = new B[10];
36 |
37 | class B {
38 |
39 | }
40 | }
41 |
42 | @Test
43 | public void testPrintable() {
44 | String print = GraphLayout.parseInstance(new A()).toPrintable();
45 | Assert.assertTrue(print, print.contains("int[]"));
46 | Assert.assertTrue(print, print.contains(".A.B[]"));
47 | }
48 |
49 | @Test
50 | public void testFootprint() {
51 | String print = GraphLayout.parseInstance(new A().new B()).toFootprint();
52 | Assert.assertTrue(print, print.contains(".A.B[]"));
53 | Assert.assertTrue(print, print.contains(".A.B"));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/util/ByteClassLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2017, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package org.openjdk.jol.util;
27 |
28 | import java.net.URL;
29 | import java.net.URLClassLoader;
30 | import java.util.HashMap;
31 | import java.util.Map;
32 |
33 | public class ByteClassLoader extends URLClassLoader {
34 | private final Map customClasses;
35 |
36 | public ByteClassLoader() {
37 | super(new URL[] {});
38 | customClasses = new HashMap<>();
39 | }
40 |
41 | @Override
42 | public Class> findClass(final String name) throws ClassNotFoundException {
43 | if (customClasses.containsKey(name)) {
44 | byte[] bs = customClasses.get(name);
45 | return defineClass(name, bs, 0, bs.length);
46 | }
47 | return super.findClass(name);
48 | }
49 |
50 | public void put(String name, byte[] bytes) {
51 | customClasses.put(name, bytes);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/provider/impl/FixedFieldNameAttributesProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider.impl;
26 |
27 | import org.openjdk.jol.ljv.provider.FieldAttributesProvider;
28 |
29 | import java.lang.reflect.Field;
30 | import java.util.Objects;
31 |
32 | public class FixedFieldNameAttributesProvider implements FieldAttributesProvider {
33 | private final String fieldName;
34 | private final String attributes;
35 |
36 | public FixedFieldNameAttributesProvider(String fieldName, String attributes) {
37 | this.fieldName = Objects.requireNonNull(fieldName);
38 | this.attributes = Objects.requireNonNull(attributes);
39 | }
40 |
41 | @Override
42 | public String getAttribute(Field field, Object val) {
43 | if (this.fieldName.equals(field.getName())) {
44 | return attributes;
45 | } else {
46 | return "";
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/Introspection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | import org.openjdk.jol.ljv.nodes.Node;
28 |
29 | import java.lang.reflect.Field;
30 | import java.util.List;
31 |
32 | public interface Introspection {
33 |
34 | Node parseGraph(Object obj, String name, boolean isPrimitive, Field field);
35 |
36 | List getChildren(Object obj);
37 |
38 | String getObjClassName(Object obj, boolean useToStringAsClassName);
39 |
40 | Field[] getObjFields(Object obj);
41 |
42 | int countObjectPrimitiveFields(Object obj);
43 |
44 | boolean hasPrimitiveFields(Object obj);
45 |
46 | boolean objectFieldIsPrimitive(Field field, Object obj);
47 |
48 | boolean canBeConvertedToString(Object obj);
49 |
50 | boolean canTreatObjAsPrimitive(Object obj);
51 |
52 | boolean canTreatObjAsArrayOfPrimitives(Object obj);
53 |
54 | boolean canTreatClassAsPrimitive(Class> cz);
55 | }
56 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/nodes/Node.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.nodes;
26 |
27 | import org.openjdk.jol.ljv.Visualization;
28 |
29 | import java.util.HashMap;
30 |
31 | public abstract class Node {
32 |
33 | private final Object value;
34 | private String name;
35 | private String attributes;
36 |
37 | public Node(Object obj, String name) {
38 | this.value = obj;
39 | this.name = name;
40 | }
41 |
42 | public Object getValue() {
43 | return value;
44 | }
45 |
46 | public String getName() {
47 | return name;
48 | }
49 |
50 | public void setName(String name) {
51 | this.name = name;
52 | }
53 |
54 | public void setAttributes(String attributes) {
55 | this.attributes = attributes;
56 | }
57 |
58 | public String getAttributes() {
59 | return attributes;
60 | }
61 |
62 | abstract public void visit(Visualization v);
63 | }
64 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/vm/HotspotUnsafeTest.java:
--------------------------------------------------------------------------------
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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm;
26 |
27 | import org.junit.Test;
28 |
29 | import java.lang.management.ManagementFactory;
30 | import java.util.Optional;
31 |
32 | import static org.apache.commons.lang3.StringUtils.substringAfter;
33 | import static org.junit.Assert.assertEquals;
34 |
35 | public class HotspotUnsafeTest {
36 | @Test
37 | public void testAlignment(){
38 | assertEquals(expectedAlignment(), VM.current().objectAlignment());
39 | }
40 |
41 | private int expectedAlignment() {
42 | Optional alignmentProperty = ManagementFactory.getRuntimeMXBean().getInputArguments().stream()
43 | .filter(arg -> arg.contains("-XX:ObjectAlignmentInBytes"))
44 | .findAny();
45 | return alignmentProperty
46 | .map(alignment -> Integer.parseInt(substringAfter(alignment, "=")))
47 | .orElse(8);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/util/SimpleStack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Red Hat Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.util;
26 |
27 | import java.util.Arrays;
28 |
29 | /**
30 | * Stack implementation optimized for JOL uses. Cuts corners where it can.
31 | * @param
32 | */
33 | public class SimpleStack {
34 | Object[] elements;
35 | int head;
36 |
37 | public SimpleStack() {
38 | head = -1;
39 | elements = new Object[2];
40 | }
41 |
42 | private void resize() {
43 | elements = Arrays.copyOf(elements, elements.length * 2);
44 | }
45 |
46 | public boolean isEmpty() {
47 | return head == -1;
48 | }
49 |
50 | public void push(E e) {
51 | head++;
52 | if (head == elements.length) {
53 | resize();
54 | }
55 | elements[head] = e;
56 | }
57 |
58 | public E pop() {
59 | Object e = elements[head];
60 | elements[head] = null;
61 | head--;
62 | return (E) e;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/sa/Task.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm.sa;
26 |
27 | import java.io.Serializable;
28 |
29 | /**
30 | *
31 | * Interface for processors which do some stuff via Hotspot Serviceability Agent API on Hotspot internals.
32 | *
33 | *
34 | *
35 | * {@link Task} implementations must be fully (including its fields) serializable.
36 | * So if there is any field will not be serialized, it must be ignored or serialization logic must be customized.
37 | * Please see http://www.oracle.com/technetwork/articles/java/javaserial-1536170.html for more details.
38 | *
39 | *
40 | * @see Result
41 | *
42 | * @author Serkan Ozal
43 | */
44 | interface Task extends Serializable {
45 |
46 | /**
47 | * Processes {@link Task}'s own logic over Hotspot Serviceability Agent.
48 | *
49 | * @return the {@link Result} instance as result
50 | */
51 | Result process();
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/Visualization.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | import org.openjdk.jol.ljv.nodes.ArrayNode;
28 | import org.openjdk.jol.ljv.nodes.Node;
29 | import org.openjdk.jol.ljv.nodes.ObjectNode;
30 |
31 | public interface Visualization {
32 | void diagramBegin();
33 |
34 | String diagramEnd();
35 |
36 | boolean alreadyVisualized(Object obj);
37 |
38 | void visitNull();
39 |
40 | void visitArrayBegin(ArrayNode arrayNode);
41 |
42 | void visitArrayElement(ArrayNode arrayNode, String element, int elementIndex);
43 |
44 | void visitArrayElementObjectConnection(Object array, int elementIndex, Object obj);
45 |
46 | void visitArrayEnd(Object array);
47 |
48 | void visitObjectBegin(ObjectNode objectNode);
49 |
50 | void visitObjectPrimitiveField(String fieldName, String fieldValueStr);
51 |
52 | void visitObjectEnd(Object obj);
53 |
54 | void visitObjectFieldRelationWithNonPrimitiveObject(Object obj, Node childNode, String ljvFieldAttributes);
55 | }
56 |
--------------------------------------------------------------------------------
/jol-cli/src/main/java/org/openjdk/jol/operations/EstimatedModels.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023, Red Hat, Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.operations;
26 |
27 | import org.openjdk.jol.datamodel.*;
28 | import org.openjdk.jol.layouters.RawLayouter;
29 |
30 | public class EstimatedModels {
31 |
32 | static final DataModel[] MODELS_JDK8 = new DataModel[]{
33 | new Model32(),
34 | new Model64(false, false, 8),
35 | new Model64(true, true, 8),
36 | new Model64(true, true, 16),
37 | };
38 |
39 | static final DataModel[] MODELS_JDK15 = new DataModel[]{
40 | new Model64(false, true, 8),
41 | new Model64(false, true, 16),
42 | };
43 |
44 | static final DataModel[] MODELS_LILLIPUT = new DataModel[]{
45 | new Model64_Lilliput(false, 8, 1),
46 | new Model64_Lilliput(true, 8, 1),
47 | new Model64_Lilliput(true, 16, 1),
48 | new Model64_Lilliput(false, 8, 2),
49 | new Model64_Lilliput(true, 8, 2),
50 | new Model64_Lilliput(true, 16, 2),
51 | };
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/layouters/FieldAllocationType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.layouters;
26 |
27 | import org.openjdk.jol.info.FieldData;
28 |
29 | enum FieldAllocationType {
30 | OOP, // Oops
31 | BYTE, // Boolean, Byte
32 | SHORT, // shorts, char
33 | WORD, // ints
34 | DOUBLE, // aligned long or double
35 | ;
36 |
37 | static FieldAllocationType allocationTypeFor(FieldData field) {
38 | switch (field.typeClass()) {
39 | case "boolean":
40 | case "byte":
41 | return FieldAllocationType.BYTE;
42 | case "short":
43 | case "char":
44 | return FieldAllocationType.SHORT;
45 | case "int":
46 | case "float":
47 | return FieldAllocationType.WORD;
48 | case "long":
49 | case "double":
50 | return FieldAllocationType.DOUBLE;
51 | default:
52 | return FieldAllocationType.OOP;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/jol-benchmarks/src/main/java/org/openjdk/jol/LinkedChainBench.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Red Hat Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol;
26 |
27 | import org.openjdk.jmh.annotations.*;
28 | import org.openjdk.jol.info.GraphLayout;
29 | import org.openjdk.jol.info.GraphStats;
30 |
31 | import java.util.concurrent.TimeUnit;
32 |
33 | @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
34 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
35 | @Fork(1)
36 | @BenchmarkMode(Mode.AverageTime)
37 | @OutputTimeUnit(TimeUnit.NANOSECONDS)
38 | @State(Scope.Benchmark)
39 | public class LinkedChainBench {
40 |
41 | @Param("1000")
42 | private int size;
43 |
44 | Node linkedChain;
45 |
46 | @Setup
47 | public void setup() {
48 | linkedChain = new Node(null);
49 | for (int c = 0; c < size; c++) {
50 | linkedChain = new Node(linkedChain);
51 | }
52 | }
53 |
54 | public static class Node {
55 | private Node n;
56 | Node(Node n) { this.n = n; }
57 | }
58 |
59 | @Benchmark
60 | public long linkedChain() {
61 | return GraphStats.parseInstance(linkedChain).totalSize();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/info/GraphStats.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.info;
26 |
27 | /**
28 | * Light-weight statistics about the object graph.
29 | */
30 | public class GraphStats {
31 |
32 | /**
33 | * Parse the object graph starting from the given instance.
34 | *
35 | * @param roots root instances to start from
36 | * @return object graph
37 | */
38 | public static GraphStats parseInstance(Object... roots) {
39 | return new GraphStatsWalker().walk(roots);
40 | }
41 |
42 | private long totalCount;
43 | private long totalSize;
44 |
45 | void addRecord(long size) {
46 | totalCount++;
47 | totalSize += size;
48 | }
49 |
50 | /**
51 | * Answer the total instance count
52 | *
53 | * @return total instance count
54 | */
55 | public long totalCount() {
56 | return totalCount;
57 | }
58 |
59 | /**
60 | * Answer the total instance footprint
61 | *
62 | * @return total instance footprint, bytes
63 | */
64 | public long totalSize() {
65 | return totalSize;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.wrappedObjects.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
10 | >];
11 | n2[label=<
12 |
13 |
14 | Integer
15 |
16 |
17 | value: 42
18 |
19 |
20 | >];
21 | n1 -> n2[label="i1",fontsize=12];
22 | n1 -> n2[label="i2",fontsize=12];
23 | n3[label=<
24 |
25 |
26 | Integer
27 |
28 |
29 | value: 2020
30 |
31 |
32 | >];
33 | n1 -> n3[label="i3",fontsize=12];
34 | n4[label=<
35 |
36 |
37 | Integer
38 |
39 |
40 | value: 2020
41 |
42 |
43 | >];
44 | n1 -> n4[label="i4",fontsize=12];
45 | n5[label=<
46 |
47 |
48 | String
49 |
50 |
51 | hash: 0
52 |
53 |
54 | >];
55 | n6[label=<
56 |
57 |
58 | char[]
59 | H
60 | e
61 | l
62 | l
63 | o
64 | W
65 | o
66 | r
67 | l
68 | d
69 |
70 |
71 | >];
72 | n5 -> n6[label="value",fontsize=12];
73 | n1 -> n5[label="s1",fontsize=12];
74 | n7[label=<
75 |
76 |
77 | String
78 |
79 |
80 | hash: 0
81 |
82 |
83 | >];
84 | n8[label=<
85 |
86 |
87 | char[]
88 | H
89 | E
90 | L
91 | L
92 |
93 | O
94 |
95 |
96 | >];
97 | n7 -> n8[label="value",fontsize=12];
98 | n1 -> n7[label="s2",fontsize=12];
99 | n1 -> n5[label="s3",fontsize=12];
100 | }
101 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/ClassLayoutArraysTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.openjdk.jol.info.ClassLayout;
6 | import org.openjdk.jol.vm.VM;
7 |
8 | import java.lang.reflect.Array;
9 |
10 | public class ClassLayoutArraysTest {
11 |
12 | static final Class>[] TYPES = new Class>[]{
13 | boolean.class,
14 | byte.class,
15 | short.class,
16 | char.class,
17 | int.class,
18 | float.class,
19 | long.class,
20 | double.class,
21 | Object.class,
22 | };
23 |
24 | @Test
25 | public void arraySizes_0() {
26 | doArraySizeFor(0);
27 | }
28 |
29 | @Test
30 | public void arraySizes_10000() {
31 | doArraySizeFor(10000);
32 | }
33 |
34 | @Test
35 | public void arraySizes_halfMax() {
36 | doArraySizeFor(Integer.MAX_VALUE / 2 - 10);
37 | }
38 |
39 | @Test
40 | public void arraySizes_max() {
41 | doArraySizeFor(Integer.MAX_VALUE - 10);
42 | }
43 |
44 | private void doArraySizeFor(int size) {
45 | for (Class> cl : TYPES) {
46 | Object o;
47 | try {
48 | o = Array.newInstance(cl, size);
49 | } catch (OutOfMemoryError e) {
50 | // Oh well, moving on.
51 | continue;
52 | }
53 | ClassLayout l = ClassLayout.parseInstance(o);
54 |
55 | int elementSize = VM.current().arrayIndexScale(cl.getName());
56 |
57 | // At least the header size, plus the element storage.
58 | // At most the alignment tail and the array base alignment.
59 | long expectedMin = l.headerSize() + (long) size * elementSize;
60 | long expectedMax = expectedMin + VM.current().objectAlignment() + 4;
61 |
62 | long actual = l.instanceSize();
63 |
64 | Assert.assertTrue(cl + " array instance size is not within range: actual = " + actual +
65 | ", expected range = [" + expectedMin + ", " + expectedMax + "]",
66 | (actual >= expectedMin && actual <= expectedMax));
67 |
68 | if (l.instanceSize() <= 0) {
69 | Assert.fail(cl + "[" + size + "] is not positive: " + l.instanceSize());
70 | }
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/provider/impl/ChangingArrayElementHighlighterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv.provider.impl;
26 |
27 | import org.junit.Test;
28 | import org.junit.Assert;
29 | import org.openjdk.jol.ljv.VersionGuardedTest;
30 |
31 | import static org.junit.Assume.assumeTrue;
32 | import static org.openjdk.jol.ljv.provider.impl.ChangingArrayElementHighlighter.HIGHLIGHT;
33 |
34 | public class ChangingArrayElementHighlighterTest extends VersionGuardedTest {
35 |
36 | ChangingArrayElementHighlighter provider = new ChangingArrayElementHighlighter();
37 |
38 | @Test
39 | public void checksChangedElements() {
40 | assumeTrue(is8());
41 | int[] arr = new int[]{1, 2, 3};
42 | for (int i = 0; i < arr.length; i++) {
43 |
44 | Assert.assertEquals("", provider.getAttribute(arr, i));
45 | }
46 | arr[0] = 2;
47 | arr[2] = 4;
48 |
49 | Assert.assertEquals(HIGHLIGHT, provider.getAttribute(arr, 0));
50 | Assert.assertEquals("", provider.getAttribute(arr, 1));
51 | Assert.assertEquals(HIGHLIGHT, provider.getAttribute(arr, 2));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/ljv/Quote.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | public final class Quote {
28 |
29 | private Quote() {
30 |
31 | }
32 |
33 | private static final String quotable = "\"<>{}|";
34 |
35 | private static final String canAppearUnquotedInLabelChars = " $&*@#!-+()^%;[],;.=";
36 |
37 | private static boolean canAppearUnquotedInLabel(char c) {
38 | return canAppearUnquotedInLabelChars.indexOf(c) != -1 ||
39 | Character.isLetter(c) || Character.isDigit(c);
40 | }
41 |
42 | public static String quote(String s) {
43 | StringBuilder sb = new StringBuilder();
44 | for (int i = 0, n = s.length(); i < n; i++) {
45 | char c = s.charAt(i);
46 | if (quotable.indexOf(c) != -1) {
47 | sb.append('\\').append(c);
48 | } else {
49 | if (canAppearUnquotedInLabel(c)) {
50 | sb.append(c);
51 | } else {
52 | sb.append("\\\\0u").append(Integer.toHexString(c));
53 | }
54 | }
55 | }
56 | return sb.toString();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectInternals.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.operations;
26 |
27 | import org.openjdk.jol.info.ClassLayout;
28 |
29 | import java.lang.reflect.Constructor;
30 |
31 | import static java.lang.System.out;
32 |
33 | /**
34 | * @author Aleksey Shipilev
35 | */
36 | public class ObjectInternals extends ClasspathedOperation {
37 |
38 | @Override
39 | public String label() {
40 | return "internals";
41 | }
42 |
43 | @Override
44 | public String description() {
45 | return "Show object internals: field layout, default contents, object header";
46 | }
47 |
48 | public void runWith(Class> klass) throws Exception {
49 | try {
50 | Object o = tryInstantiate(klass);
51 | out.println(ClassLayout.parseInstance(o).toPrintable());
52 | } catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) {
53 | out.println("Failed to find matching constructor, falling back to class-only introspection.");
54 | out.println();
55 | out.println(ClassLayout.parseClass(klass).toPrintable());
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/ZGCAddress.java:
--------------------------------------------------------------------------------
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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm;
26 |
27 | /**
28 | * Utility class for normalizing ZGC addresses by removing color bits
29 | *
30 | * @see Layout description
31 | */
32 | class ZGCAddress {
33 | private static final long REMAPPED_BITS_MASK = 0b1111L << 12;
34 | private static final long CLEAR_UNUSED_BITS_MASK = (1L << 46) - 1;
35 | private static final long COLOR_BITS_COUNT = 16;
36 | private static final boolean IS_ARM64 = "aarch64".equals(System.getProperty("os.arch"));
37 |
38 | static long uncolorize(long address) {
39 | return IS_ARM64 ? uncolorizeAarch(address) : uncolorizeNonAarch(address);
40 | }
41 |
42 | private static long uncolorizeNonAarch(long address) {
43 | int shift = Long.numberOfTrailingZeros(address & REMAPPED_BITS_MASK) + 1;
44 | return (address >> shift) & CLEAR_UNUSED_BITS_MASK;
45 | }
46 |
47 | private static long uncolorizeAarch(long address) {
48 | return (address >> COLOR_BITS_COUNT) & CLEAR_UNUSED_BITS_MASK;
49 | }
50 |
51 | private ZGCAddress() {}
52 | }
53 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/info/GraphPathRecord.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.info;
26 |
27 | import org.openjdk.jol.vm.VM;
28 |
29 | /**
30 | * Object path in object graph.
31 | *
32 | * @author Aleksey Shipilev
33 | */
34 | public abstract class GraphPathRecord {
35 | protected final GraphPathRecord parent;
36 | private final int depth;
37 | private final Object obj;
38 | private long size;
39 |
40 | GraphPathRecord(GraphPathRecord parent, int depth, Object obj) {
41 | this.parent = parent;
42 | this.obj = obj;
43 | this.depth = depth;
44 | }
45 |
46 | final Object obj() {
47 | return obj;
48 | }
49 |
50 | public abstract String path();
51 |
52 | public final Class> klass() {
53 | return obj.getClass();
54 | }
55 |
56 | public final long size() {
57 | if (size == 0) {
58 | // Object size would not change, fine to compute lazily.
59 | size = VM.current().sizeOf(obj);
60 | }
61 | return size;
62 | }
63 |
64 | final void setSize(long size) {
65 | this.size = size;
66 | }
67 |
68 | final int depth() {
69 | return depth;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectExternals.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.operations;
26 |
27 | import org.openjdk.jol.info.GraphLayout;
28 |
29 | import java.lang.reflect.Constructor;
30 |
31 | import static java.lang.System.out;
32 |
33 | /**
34 | * @author Aleksey Shipilev
35 | */
36 | public class ObjectExternals extends ClasspathedOperation {
37 |
38 | @Override
39 | public String label() {
40 | return "externals";
41 | }
42 |
43 | @Override
44 | public String description() {
45 | return "Show object externals: objects reachable from a given instance";
46 | }
47 |
48 | public void runWith(Class> klass) throws Exception {
49 | try {
50 | Object o = tryInstantiate(klass);
51 | out.println(GraphLayout.parseInstance(o).toPrintable());
52 | } catch (NoSuchMethodException | InstantiationException e) {
53 | throw new IllegalStateException("Instantiation exception, does the class have the default constructor?", e);
54 | } catch (IllegalAccessException e) {
55 | throw new IllegalStateException("Illegal access exception, does the class have the public default constructor?", e);
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/jol-cli/src/main/java/org/openjdk/jol/operations/ObjectFootprint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.operations;
26 |
27 | import org.openjdk.jol.info.GraphLayout;
28 |
29 | import java.lang.reflect.Constructor;
30 |
31 | import static java.lang.System.out;
32 |
33 | /**
34 | * @author Aleksey Shipilev
35 | */
36 | public class ObjectFootprint extends ClasspathedOperation {
37 |
38 | @Override
39 | public String label() {
40 | return "footprint";
41 | }
42 |
43 | @Override
44 | public String description() {
45 | return "Show the footprint of all objects reachable from a sample instance";
46 | }
47 |
48 | public void runWith(Class> klass) throws Exception {
49 | try {
50 | Object o = tryInstantiate(klass);
51 | out.println(GraphLayout.parseInstance(o).toFootprint());
52 | } catch (NoSuchMethodException | InstantiationException e) {
53 | throw new IllegalStateException("Instantiation exception, does the class have the default constructor?", e);
54 | } catch (IllegalAccessException e) {
55 | throw new IllegalStateException("Illegal access exception, does the class have the public default constructor?", e);
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/util/Multimap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Amazon.com Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.util;
26 |
27 | import java.util.*;
28 |
29 | /**
30 | * Naive HashMultimap.
31 | *
32 | * @param key type
33 | * @param value type
34 | */
35 | public class Multimap {
36 |
37 | private final Map> map = new HashMap<>();
38 |
39 | public void put(K k, V v) {
40 | List vs = map.get(k);
41 | if (vs == null) {
42 | vs = new ArrayList<>();
43 | map.put(k, vs);
44 | }
45 | vs.add(v);
46 | }
47 |
48 | public void putEmpty(K k) {
49 | List vs = map.get(k);
50 | if (vs == null) {
51 | vs = new ArrayList<>();
52 | map.put(k, vs);
53 | }
54 | }
55 |
56 | public List get(K k) {
57 | if (map.containsKey(k)) {
58 | return Collections.unmodifiableList(map.get(k));
59 | } else {
60 | return Collections.emptyList();
61 | }
62 | }
63 |
64 | public Collection keys() {
65 | return map.keySet();
66 | }
67 |
68 | public List remove(K k) {
69 | return map.remove(k);
70 | }
71 |
72 | public boolean contains(K k) {
73 | return map.containsKey(k);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_01_Basic.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_01_Basic {
42 |
43 | /*
44 | * This sample showcases the basic field layout.
45 | * You can see a few notable things here:
46 | * a) how much the object header consumes;
47 | * b) how fields are laid out;
48 | * c) how the external alignment beefs up the object size
49 | */
50 |
51 | public static void main(String[] args) {
52 | out.println(VM.current().details());
53 | out.println(ClassLayout.parseClass(A.class).toPrintable());
54 | }
55 |
56 | public static class A {
57 | boolean f;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_17_ArrayLength.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, Red Hat, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_17_ArrayLength {
42 |
43 | /*
44 | * The example for array length.
45 | *
46 | * Array length is not the part of array type, so VMs need another
47 | * slot in header to store the array length. This can be demonstrated
48 | * by this example.
49 | */
50 |
51 | public static void main(String[] args) {
52 | out.println(VM.current().details());
53 |
54 | for (int c = 0; c < 8; c++) {
55 | out.println("**** int[" + c + "]");
56 | out.println(ClassLayout.parseInstance(new int[c]).toPrintable());
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/info/ClassLayoutInstanceTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.info;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.openjdk.jol.info.ClassLayout;
6 | import org.openjdk.jol.vm.VM;
7 |
8 | import java.lang.reflect.Array;
9 |
10 | public class ClassLayoutInstanceTest {
11 |
12 | static class A {
13 |
14 | }
15 |
16 | static class B {
17 | A a = new A();
18 | }
19 |
20 | static class C extends B {
21 |
22 | }
23 |
24 | @Test
25 | public void testPrint() {
26 | ClassLayout.parseInstance(new A()).toPrintable();
27 | ClassLayout.parseInstance(new B()).toPrintable();
28 |
29 | ClassLayout.parseClass(A.class).toPrintable();
30 | ClassLayout.parseClass(B.class).toPrintable();
31 |
32 | ClassLayout.parseClass(A.class).toPrintable(new A());
33 | ClassLayout.parseClass(B.class).toPrintable(new B());
34 | }
35 |
36 | @Test
37 | public void testInconsistentTypes() {
38 | try {
39 | ClassLayout.parseClass(A.class).toPrintable(new B());
40 | Assert.fail("Trying to pass instance B over the class A succeeded");
41 | } catch (Exception e) {
42 | // expected
43 | }
44 |
45 | try {
46 | ClassLayout.parseClass(B.class).toPrintable(new A());
47 | Assert.fail("Trying to pass instance A over the class B succeeded");
48 | } catch (Exception e) {
49 | // expected
50 | }
51 |
52 | try {
53 | ClassLayout.parseClass(B.class).toPrintable(new C());
54 | } catch (Exception e) {
55 | Assert.fail("Trying to pass instance C over the class B failed");
56 | }
57 | }
58 |
59 | @Test
60 | public void headers() {
61 | ClassLayout clA = ClassLayout.parseInstance(new A());
62 | ClassLayout clB = ClassLayout.parseInstance(new B());
63 |
64 | Assert.assertTrue("A header size is positive",
65 | clA.headerSize() >= 0);
66 |
67 | Assert.assertTrue("B header size is positive",
68 | clB.headerSize() >= 0);
69 |
70 | Assert.assertEquals("A and B header sizes agree",
71 | clA.headerSize(), clB.headerSize());
72 |
73 | Assert.assertTrue("A instance size agrees with A header size",
74 | clA.instanceSize() >= clA.headerSize());
75 |
76 | Assert.assertTrue("B instance size agrees with B header size",
77 | clB.instanceSize() >= clB.headerSize());
78 |
79 | Assert.assertTrue("B instance size is larger or equal A instance size",
80 | clB.instanceSize() >= clA.headerSize());
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/HashCodeCollision.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.ljv;
26 |
27 | import org.junit.Test;
28 |
29 | import java.util.*;
30 |
31 | import static org.junit.Assert.assertEquals;
32 |
33 |
34 | /**
35 | * @author Ivan Ponomarev
36 | */
37 | public class HashCodeCollision {
38 |
39 | public List genCollisionString(Integer amount) {
40 | List result = new ArrayList<>();
41 | for (int i = 0; i < amount; i++) {
42 | StringBuilder val = new StringBuilder();
43 | int mask = 1;
44 | do {
45 | val.append((i & mask) > 0 ? "BB" : "Aa");
46 | mask *= 2;
47 | } while (mask < amount);
48 | result.add(val.toString());
49 | }
50 | return result;
51 | }
52 |
53 | @Test
54 | public void testCollisions() {
55 | for (int number = 1; number < 101; number++) {
56 | List strings = genCollisionString(number);
57 | Set deduplicated = new HashSet<>(strings);
58 | //All strings are unique
59 | assertEquals(number, deduplicated.size());
60 | int hashCode = strings.get(0).hashCode();
61 | for (int i = 1; i < strings.size(); i++) {
62 | //All strings have the same hash code
63 | assertEquals(hashCode, strings.get(i).hashCode());
64 | }
65 | }
66 | }
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/ljv/approvals/LJVTest.hashMap.approved.txt:
--------------------------------------------------------------------------------
1 | digraph Java {
2 | rankdir="TB";
3 | node[shape=plaintext]
4 | n1[label=<
5 |
6 |
7 | HashMap
8 |
9 |
10 | size: 4
11 |
12 |
13 | modCount: 4
14 |
15 |
16 | threshold: 12
17 |
18 |
19 | loadFactor: 0.75
20 |
21 |
22 | >];
23 | n2[label=<
24 |
25 |
26 | Node[]
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | >];
46 | n3[label=<
47 |
48 |
49 | Node
50 |
51 |
52 | hash: 3149078
53 |
54 |
55 | key: four
56 |
57 |
58 | value: 4
59 |
60 |
61 | >];
62 | n2:f6 -> n3[label="6",fontsize=12];
63 | n4[label=<
64 |
65 |
66 | Node
67 |
68 |
69 | hash: 110183
70 |
71 |
72 | key: one
73 |
74 |
75 | value: 1
76 |
77 |
78 | >];
79 | n2:f7 -> n4[label="7",fontsize=12];
80 | n5[label=<
81 |
82 |
83 | Node
84 |
85 |
86 | hash: 115277
87 |
88 |
89 | key: two
90 |
91 |
92 | value: 2
93 |
94 |
95 | >];
96 | n6[label=<
97 |
98 |
99 | Node
100 |
101 |
102 | hash: 110338829
103 |
104 |
105 | key: three
106 |
107 |
108 | value: 3
109 |
110 |
111 | >];
112 | n5 -> n6[label="next",fontsize=12];
113 | n2:f13 -> n5[label="13",fontsize=12];
114 | n1 -> n2[label="table",fontsize=12];
115 | }
116 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_02_Alignment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_02_Alignment {
42 |
43 | /*
44 | * This is the more advanced field layout example.
45 | *
46 | * Because the underlying hardware platform often requires aligned accesses
47 | * to maintain the performance and correctness, it is expected the fields
48 | * are aligned by their size. For booleans it does not mean anything, but
49 | * for longs it's different. In this example, we can see the long field
50 | * is indeed aligned for 8 bytes, sometimes making the gap after the
51 | * object header.
52 | */
53 |
54 | public static void main(String[] args) {
55 | out.println(VM.current().details());
56 | out.println(ClassLayout.parseClass(A.class).toPrintable());
57 | }
58 |
59 | public static class A {
60 | long f;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_08_Class.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_08_Class {
42 |
43 | /*
44 | * Another example of special treatment for some fields.
45 | *
46 | * If you run this example, you can see the large gap in instance field block.
47 | * There are no Java fields that could claim that block, hence there are no
48 | * "hidden" fields, like in the example before. This time, VM "injects" some
49 | * of the fields into the Class, to store some of the meta-information there.
50 | *
51 | * See:
52 | * https://github.com/openjdk/jdk/blob/fd45694c58452635db572cb55e5a1b2cb7bc34b2/src/hotspot/share/classfile/javaClasses.hpp#L219-L226
53 | */
54 |
55 | public static void main(String[] args) {
56 | out.println(VM.current().details());
57 | out.println(ClassLayout.parseClass(Class.class).toPrintable());
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_11_ClassWord.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_11_ClassWord {
42 |
43 | /*
44 | * This is the example to have insight into object headers.
45 | *
46 | * In HotSpot, object header consists of two parts: mark word,
47 | * and class word. We can clearly see the class word by analysing
48 | * two empty instances of two distinct classes. See the difference
49 | * in class word, that difference is the reference to class.
50 | */
51 |
52 | public static void main(String[] args) {
53 | out.println(VM.current().details());
54 | out.println(ClassLayout.parseInstance(new A()).toPrintable());
55 | out.println(ClassLayout.parseInstance(new B()).toPrintable());
56 | }
57 |
58 | public static class A {
59 | // no fields
60 | }
61 |
62 | public static class B {
63 | // no fields
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/jol-benchmarks/src/main/java/org/openjdk/jol/GraphInstanceBench.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Red Hat Inc. 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol;
26 |
27 | import org.openjdk.jmh.annotations.*;
28 | import org.openjdk.jol.info.GraphLayout;
29 |
30 | import java.util.concurrent.TimeUnit;
31 |
32 | @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
33 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
34 | @Fork(1)
35 | @BenchmarkMode(Mode.AverageTime)
36 | @OutputTimeUnit(TimeUnit.NANOSECONDS)
37 | @State(Scope.Benchmark)
38 | public class GraphInstanceBench {
39 |
40 | @Param({"1", "100", "10000"})
41 | int size;
42 |
43 | private Integer[] arr;
44 |
45 | @Setup
46 | public void setup() {
47 | arr = new Integer[size];
48 | for (int c = 0; c < size; c++) {
49 | arr[c] = new Integer(c);
50 | }
51 | }
52 |
53 | @Benchmark
54 | public GraphLayout onlyCollect() {
55 | return GraphLayout.parseInstance((Object) arr);
56 | }
57 |
58 | @Benchmark
59 | public String toFootprint() {
60 | return GraphLayout.parseInstance((Object) arr).toFootprint();
61 | }
62 |
63 | @Benchmark
64 | public String toPrintable() {
65 | return GraphLayout.parseInstance((Object) arr).toPrintable();
66 | }
67 |
68 | @Benchmark
69 | public long totalCount() {
70 | return GraphLayout.parseInstance((Object) arr).totalCount();
71 | }
72 |
73 | @Benchmark
74 | public long totalSize() {
75 | return GraphLayout.parseInstance((Object) arr).totalSize();
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/layouters/HotspotLayouterRealTest.java:
--------------------------------------------------------------------------------
1 | package org.openjdk.jol.layouters;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.openjdk.jol.datamodel.ModelVM;
6 | import org.openjdk.jol.datamodel.DataModel;
7 | import org.openjdk.jol.info.ClassData;
8 | import org.openjdk.jol.info.ClassLayout;
9 | import org.openjdk.jol.util.ClassGenerator;
10 |
11 | import java.util.*;
12 |
13 | public class HotspotLayouterRealTest {
14 |
15 | private static final int ITERATIONS = 20000;
16 |
17 | private int getVersion() {
18 | try {
19 | return Integer.parseInt(System.getProperty("java.specification.version"));
20 | } catch (Exception e) {
21 | return -1;
22 | }
23 | }
24 |
25 | @Test
26 | public void testSingleClass() throws Exception {
27 | tryWithClasses(1, 5, getVersion());
28 | }
29 |
30 | @Test
31 | public void testTwoClasses() throws Exception {
32 | tryWithClasses(2, 5, getVersion());
33 | }
34 |
35 | @Test
36 | public void testArrays() {
37 | int version = getVersion();
38 | for (int c = 0; c < 128; c++) {
39 | tryWithArrays(new boolean[c], version);
40 | tryWithArrays(new byte[c], version);
41 | tryWithArrays(new char[c], version);
42 | tryWithArrays(new int[c], version);
43 | tryWithArrays(new float[c], version);
44 | tryWithArrays(new long[c], version);
45 | tryWithArrays(new double[c], version);
46 | tryWithArrays(new Object[c], version);
47 | }
48 | }
49 |
50 | public void tryWithArrays(Object array, int jdkVersion) {
51 | ClassLayout actual = ClassLayout.parseInstance(array);
52 | ClassData cd = ClassData.parseInstance(array);
53 |
54 | HotSpotLayouter layouter = new HotSpotLayouter(new ModelVM(), jdkVersion);
55 | ClassLayout model = layouter.layout(cd);
56 |
57 | System.out.println(actual);
58 | System.out.println(model);
59 |
60 | Assert.assertEquals(model, actual);
61 | }
62 |
63 | public void tryWithClasses(int hierarchyDepth, int fieldsPerClass, int jdkVersion) throws Exception {
64 | Random seeder = new Random();
65 | HotSpotLayouter layouter = new HotSpotLayouter(new ModelVM(), jdkVersion);
66 |
67 | for (int c = 0; c < ITERATIONS; c++) {
68 | int seed = seeder.nextInt();
69 | Class> cl = ClassGenerator.generate(new Random(seed), hierarchyDepth, fieldsPerClass);
70 |
71 | ClassLayout actual = ClassLayout.parseClass(cl);
72 | ClassData cd = ClassData.parseClass(cl);
73 |
74 | ClassLayout model = layouter.layout(cd);
75 | Assert.assertEquals(model, actual);
76 | }
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/datamodel/DataModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2013, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.datamodel;
26 |
27 | /**
28 | * Describes the data model, notably,
29 | * the basic types sizes.
30 | *
31 | * @author Aleksey Shipilev
32 | */
33 | public interface DataModel {
34 |
35 | /**
36 | * Return the mark header size.
37 | * @return mark header size in bytes.
38 | */
39 | int markHeaderSize();
40 |
41 | /**
42 | * Return the class header size.
43 | * @return class header size in bytes.
44 | */
45 | int classHeaderSize();
46 |
47 | /**
48 | * Return the array length header size.
49 | * @return array length header size in bytes.
50 | */
51 | int arrayLengthHeaderSize();
52 |
53 | /**
54 | * Return the object header size.
55 | *
56 | * @return object header size in bytes.
57 | */
58 | int headerSize();
59 |
60 | /**
61 | * Return the array header size.
62 | *
63 | * @return object header size in bytes.
64 | */
65 | int arrayHeaderSize();
66 |
67 | /**
68 | * Return the size of the type.
69 | *
70 | * @param klass string representation of the type.
71 | * @return size in bytes.
72 | */
73 | int sizeOf(String klass);
74 |
75 | /**
76 | * Return the object alignment.
77 | *
78 | * @return minimal object alignment
79 | */
80 | int objectAlignment();
81 |
82 | /**
83 | * Machine address size.
84 | *
85 | * @return machine address size, in bytes
86 | */
87 | int addressSize();
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/vm/Experiments.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm;
26 |
27 | class Experiments {
28 |
29 | public static class CompressedOopsClass {
30 | public Object obj1;
31 | public Object obj2;
32 | }
33 |
34 | public static class HeaderClass {
35 | public boolean b1;
36 | }
37 |
38 | public static class MyObject0 {
39 |
40 | }
41 |
42 | public static class MyObject1 {
43 |
44 | }
45 |
46 | public static class MyObject2 {
47 | private boolean b;
48 | }
49 |
50 | public static class MyObject3 {
51 | private int i;
52 | }
53 |
54 | public static class MyObject4 {
55 | private long l;
56 | }
57 |
58 | public static class MyObject5 {
59 | private Object o;
60 | }
61 |
62 | public static class MyBooleans4 {
63 | private boolean f1, f2, f3, f4;
64 | }
65 |
66 | public static class MyBytes4 {
67 | private byte f1, f2, f3, f4;
68 | }
69 |
70 | public static class MyShorts4 {
71 | private short f1, f2, f3, f4;
72 | }
73 |
74 | public static class MyChars4 {
75 | private char f1, f2, f3, f4;
76 | }
77 |
78 | public static class MyInts4 {
79 | private int f1, f2, f3, f4;
80 | }
81 |
82 | public static class MyFloats4 {
83 | private float f1, f2, f3, f4;
84 | }
85 |
86 | public static class MyLongs4 {
87 | private long f1, f2, f3, f4;
88 | }
89 |
90 | public static class MyDoubles4 {
91 | private double f1, f2, f3, f4;
92 | }
93 | }
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_04_Inheritance.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_04_Inheritance {
42 |
43 | /*
44 | * This is the example how VM lays out the fields in the hierarchy.
45 | *
46 | * The important invariant for JVM to maintain is laying out the
47 | * accessible fields at the same offsets regardless of the class
48 | * the field is being accessed through. That is, for classes B and C
49 | * below the field A.a should reside on the same offset. This prompts
50 | * VM to lay out the superclass fields first.
51 | */
52 |
53 | public static void main(String[] args) {
54 | out.println(VM.current().details());
55 | out.println(ClassLayout.parseClass(C.class).toPrintable());
56 | }
57 |
58 | public static class A {
59 | int a;
60 | }
61 |
62 | public static class B extends A {
63 | int b;
64 | }
65 |
66 | public static class C extends B {
67 | int c;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_06_HierarchyGaps.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_06_HierarchyGaps {
42 |
43 | /*
44 | * This example shows another HotSpot layout quirk.
45 | *
46 | * Prior to JDK 15, HotSpot rounds up the instance field block
47 | * up to reference size. That unfortunately yields the artificial
48 | * gaps at the end of the class.
49 | *
50 | * In JDK 15 and later, the hierarchy gaps are no longer present.
51 | *
52 | * See also:
53 | * https://bugs.openjdk.java.net/browse/JDK-8237767
54 | */
55 |
56 | public static void main(String[] args) {
57 | out.println(VM.current().details());
58 | out.println(ClassLayout.parseClass(C.class).toPrintable());
59 | }
60 |
61 | public static class A {
62 | boolean a;
63 | }
64 |
65 | public static class B extends A {
66 | boolean b;
67 | }
68 |
69 | public static class C extends B {
70 | boolean c;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/jol-core/src/main/java/org/openjdk/jol/util/IOUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2015, 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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.util;
26 |
27 | import java.io.*;
28 |
29 | public class IOUtils {
30 |
31 | private IOUtils() {
32 |
33 | }
34 |
35 | public static void safelyClose(OutputStream out) {
36 | if (out != null) {
37 | try {
38 | out.flush();
39 | } catch (IOException e) {
40 | // ignore
41 | }
42 | try {
43 | out.close();
44 | } catch (IOException e) {
45 | // ignore
46 | }
47 | }
48 | }
49 |
50 | public static void safelyClose(InputStream in) {
51 | if (in != null) {
52 | try {
53 | in.close();
54 | } catch (IOException e) {
55 | // ignore
56 | }
57 | }
58 | }
59 |
60 | public static void safelyClose(Reader reader) {
61 | if (reader != null) {
62 | try {
63 | reader.close();
64 | } catch (IOException e) {
65 | // ignore
66 | }
67 | }
68 | }
69 |
70 | public static byte[] readAllBytes(InputStream is) {
71 | try {
72 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
73 | byte[] buf = new byte[1024];
74 | int read;
75 | while ((read = is.read(buf)) != -1) {
76 | baos.write(buf, 0, read);
77 | }
78 | baos.flush();
79 | return baos.toByteArray();
80 | } catch (IOException e) {
81 | return null;
82 | }
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/jol-core/src/test/java/org/openjdk/jol/vm/ZGCAddressTest.java:
--------------------------------------------------------------------------------
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. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 | package org.openjdk.jol.vm;
26 |
27 | import org.junit.Test;
28 |
29 | import static org.junit.Assert.assertEquals;
30 |
31 | public class ZGCAddressTest {
32 | @Test
33 | public void testGenerationalZGCAddressUncolorize() {
34 | final long[] coloredAddresses;
35 | if ("aarch64".equals(System.getProperty("os.arch"))) {
36 | coloredAddresses = new long[] {
37 | // remapped bits inverted, no address and color overlap
38 | 0b00100100_00000000_00000000_00111011_10100110_10111000_11100101_00010000L,
39 | 0b00100100_00000000_00000000_00111011_10100110_10111000_11010101_00010000L,
40 | 0b00100100_00000000_00000000_00111011_10100110_10111000_10110101_00010000L,
41 | 0b00100100_00000000_00000000_00111011_10100110_10111000_01110101_00010000L
42 | };
43 | } else {
44 | coloredAddresses = new long[] {
45 | 0b00100100_00000000_00000000_00111011_10100110_10111000_10000101_00010000L,
46 | 0b00010010_00000000_00000000_00011101_11010011_01011100_01000101_00010000L,
47 | 0b00001001_00000000_00000000_00001110_11101001_10101110_00100101_00010000L,
48 | 0b00000100_10000000_00000000_00000111_01110100_11010111_00010101_00010000L,
49 | };
50 | }
51 |
52 | for (long address : coloredAddresses) {
53 | assertEquals(
54 | 0b100100_00000000_00000000_00111011_10100110_10111000L,
55 | ZGCAddress.uncolorize(address)
56 | );
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_07_Exceptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_07_Exceptions {
42 |
43 | /*
44 | * This example shows some of the fields are treated specially in VM.
45 | *
46 | * In JDK 8 and lower, you would see suspicious gap in Throwable class.
47 | * If you look in the Java source, you will see the Throwable.backtrace
48 | * field, which is not listed in the dump. This is because this field
49 | * handles the VM internal info which should not be accessible to users
50 | * under no conditions.
51 | *
52 | * In JDK 9 and later, the field is visible again and guaranteed to
53 | * contain Java-readable contents.
54 | *
55 | * See also:
56 | * https://bugs.openjdk.java.net/browse/JDK-4496456
57 | * https://bugs.openjdk.java.net/browse/JDK-8033735
58 | */
59 |
60 | public static void main(String[] args) {
61 | out.println(VM.current().details());
62 | out.println(ClassLayout.parseClass(Throwable.class).toPrintable());
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_15_IdentityHashCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Oracle America, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * * Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * * Neither the name of Oracle nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 | * THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 | package org.openjdk.jol.samples;
32 |
33 | import org.openjdk.jol.info.ClassLayout;
34 | import org.openjdk.jol.vm.VM;
35 |
36 | import static java.lang.System.out;
37 |
38 | /**
39 | * @author Aleksey Shipilev
40 | */
41 | public class JOLSample_15_IdentityHashCode {
42 |
43 | /*
44 | * The example for identity hash code.
45 | *
46 | * The identity hash code, once computed, should stay the same.
47 | * HotSpot opts to store the hash code in the mark word as well.
48 | * You can clearly see the hash code bytes in the header once
49 | * it was computed.
50 | */
51 |
52 | public static void main(String[] args) {
53 | out.println(VM.current().details());
54 |
55 | final A a = new A();
56 |
57 | ClassLayout layout = ClassLayout.parseInstance(a);
58 |
59 | out.println("**** Fresh object");
60 | out.println(layout.toPrintable());
61 |
62 | out.println("hashCode: " + Integer.toHexString(a.hashCode()));
63 | out.println();
64 |
65 | out.println("**** After identityHashCode()");
66 | out.println(layout.toPrintable());
67 | }
68 |
69 | public static class A {
70 | // no fields
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------