Skip to content

Commit

Permalink
8317285: Misspellings in hprof test lib
Browse files Browse the repository at this point in the history
Reviewed-by: sspitsyn, cjplummer
  • Loading branch information
Alex Menkov committed Oct 16, 2023
1 parent 741ae06 commit aed1e81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private static void verifyDump(File dumpFile) throws Exception {
private static List<Root> findStackRoot(List<Root> roots, ThreadObject thread) {
List<Root> result = new ArrayList<>();
for (Root root: roots) {
if (root.getRefererId() == thread.getId()) {
if (root.getReferrerId() == thread.getId()) {
result.add(root);
}
}
Expand All @@ -286,7 +286,7 @@ private static void test(Snapshot snapshot, String className) {
throw new RuntimeException("No root for " + className + " instance");
}
log(" root: " + root.getDescription());
JavaHeapObject referrer = root.getReferer();
JavaHeapObject referrer = root.getReferrer();
log(" referrer: " + referrer);
}

Expand Down
60 changes: 30 additions & 30 deletions test/lib/jdk/test/lib/hprof/model/JavaHeapObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -53,13 +53,13 @@ public abstract class JavaHeapObject extends JavaThing {
//
// Who we refer to. This is heavily optimized for space, because it's
// well worth trading a bit of speed for less swapping.
// referers and referersLen go through two phases: Building and
// resolved. When building, referers might have duplicates, but can
// be appended to. When resolved, referers has no duplicates or
// referrers and referrersLen go through two phases: Building and
// resolved. When building, referrers might have duplicates, but can
// be appended to. When resolved, referrers has no duplicates or
// empty slots.
//
private JavaThing[] referers = null;
private int referersLen = 0; // -1 when resolved
private JavaThing[] referrers = null;
private int referrersLen = 0; // -1 when resolved

public abstract JavaClass getClazz();
public abstract long getSize();
Expand All @@ -77,25 +77,25 @@ public void resolve(Snapshot snapshot) {
}

//
// Eliminate duplicates from referers, and size the array exactly.
// Eliminate duplicates from referrers, and size the array exactly.
// This sets us up to answer queries. See the comments around the
// referers data member for details.
// referrers data member for details.
//
void setupReferers() {
if (referersLen > 1) {
// Copy referers to map, screening out duplicates
void setupReferrers() {
if (referrersLen > 1) {
// Copy referrers to map, screening out duplicates
Map<JavaThing, JavaThing> map = new HashMap<JavaThing, JavaThing>();
for (int i = 0; i < referersLen; i++) {
if (map.get(referers[i]) == null) {
map.put(referers[i], referers[i]);
for (int i = 0; i < referrersLen; i++) {
if (map.get(referrers[i]) == null) {
map.put(referrers[i], referrers[i]);
}
}

// Now copy into the array
referers = new JavaThing[map.size()];
map.keySet().toArray(referers);
referrers = new JavaThing[map.size()];
map.keySet().toArray(referrers);
}
referersLen = -1;
referrersLen = -1;
}


Expand Down Expand Up @@ -134,15 +134,15 @@ public void visitReferencedObjects(JavaHeapObjectVisitor v) {
}

void addReferenceFrom(JavaHeapObject other) {
if (referersLen == 0) {
referers = new JavaThing[1]; // It was null
} else if (referersLen == referers.length) {
JavaThing[] copy = new JavaThing[(3 * (referersLen + 1)) / 2];
System.arraycopy(referers, 0, copy, 0, referersLen);
referers = copy;
if (referrersLen == 0) {
referrers = new JavaThing[1]; // It was null
} else if (referrersLen == referrers.length) {
JavaThing[] copy = new JavaThing[(3 * (referrersLen + 1)) / 2];
System.arraycopy(referrers, 0, copy, 0, referrersLen);
referrers = copy;
}
referers[referersLen++] = other;
// We just append to referers here. Measurements have shown that
referrers[referrersLen++] = other;
// We just append to referrers here. Measurements have shown that
// around 10% to 30% are duplicates, so it's better to just append
// blindly and screen out all the duplicates at once.
}
Expand All @@ -164,26 +164,26 @@ public Root getRoot() {
*
* @return an Enumeration of JavaHeapObject instances
*/
public Enumeration<JavaThing> getReferers() {
if (referersLen != -1) {
public Enumeration<JavaThing> getReferrers() {
if (referrersLen != -1) {
throw new RuntimeException("not resolved: " + getIdString());
}
return new Enumeration<JavaThing>() {

private int num = 0;

public boolean hasMoreElements() {
return referers != null && num < referers.length;
return referrers != null && num < referrers.length;
}

public JavaThing nextElement() {
return referers[num++];
return referrers[num++];
}
};
}

/**
* Given other, which the caller promises is in referers, determines if
* Given other, which the caller promises is in referrers, determines if
* the reference is only a weak reference.
*/
public boolean refersOnlyWeaklyTo(Snapshot ss, JavaThing other) {
Expand Down
26 changes: 13 additions & 13 deletions test/lib/jdk/test/lib/hprof/model/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
public class Root {

private long id; // ID of the JavaThing we refer to
private long refererId; // Thread or Class responsible for this, or 0
private int index = -1; // Index in Snapshot.roots
private long referrerId; // Thread or Class responsible for this, or 0
private int index = -1; // Index in Snapshot.roots
private int type;
private String description;
private JavaHeapObject referer = null;
private JavaHeapObject referrer = null;
private StackTrace stackTrace = null;

// Values for type. Higher values are more interesting -- see getType().
Expand All @@ -68,15 +68,15 @@ public class Root {
public final static int JAVA_STATIC = 9;


public Root(long id, long refererId, int type, String description) {
this(id, refererId, type, description, null);
public Root(long id, long referrerId, int type, String description) {
this(id, referrerId, type, description, null);
}


public Root(long id, long refererId, int type, String description,
public Root(long id, long referrerId, int type, String description,
StackTrace stackTrace) {
this.id = id;
this.refererId = refererId;
this.referrerId = referrerId;
this.type = type;
this.description = description;
this.stackTrace = stackTrace;
Expand Down Expand Up @@ -137,12 +137,12 @@ public Root mostInteresting(Root other) {
* Get the object that's responsible for this root, if there is one.
* This will be null, a Thread object, or a Class object.
*/
public JavaHeapObject getReferer() {
return referer;
public JavaHeapObject getReferrer() {
return referrer;
}

public long getRefererId() {
return refererId;
public long getReferrerId() {
return referrerId;
}

/**
Expand All @@ -161,8 +161,8 @@ public int getIndex() {
}

void resolve(Snapshot ss) {
if (refererId != 0) {
referer = ss.findThing(refererId);
if (referrerId != 0) {
referrer = ss.findThing(referrerId);
}
if (stackTrace != null) {
stackTrace.resolve(ss);
Expand Down
10 changes: 5 additions & 5 deletions test/lib/jdk/test/lib/hprof/model/Snapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void resolve(boolean calculateRefs) {
}
int count = 0;
for (JavaHeapObject t : heapObjects.values()) {
t.setupReferers();
t.setupReferrers();
++count;
if (calculateRefs && count % DOT_LIMIT == 0) {
System.out.print(".");
Expand Down Expand Up @@ -461,11 +461,11 @@ public List<ThreadObject> getThreads() {
if (curr.getRoot() != null) {
result.addElement(chain);
// Even though curr is in the rootset, we want to explore its
// referers, because they might be more interesting.
// referrers, because they might be more interesting.
}
Enumeration<JavaThing> referers = curr.getReferers();
while (referers.hasMoreElements()) {
JavaHeapObject t = (JavaHeapObject) referers.nextElement();
Enumeration<JavaThing> referrers = curr.getReferrers();
while (referrers.hasMoreElements()) {
JavaHeapObject t = (JavaHeapObject)referrers.nextElement();
if (t != null && !visited.containsKey(t)) {
if (includeWeak || !t.refersOnlyWeaklyTo(this, curr)) {
visited.put(t, t);
Expand Down

1 comment on commit aed1e81

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.