Skip to content

Commit dfcd9d5

Browse files
committed
8295320: [BACKOUT] 8276687 Remove support for JDK 1.4.1 PerfData shared memory files
Reviewed-by: redestad, kevinw
1 parent 2da079c commit dfcd9d5

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/LocalVmManager.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,7 @@
4444
public class LocalVmManager {
4545
private FilenameFilter userDirFilter;
4646
private FilenameFilter userDirFileFilter;
47+
private FilenameFilter oldtmpFileFilter;
4748

4849
/**
4950
* Creates a LocalVmManager instance for the local system.
@@ -52,7 +53,7 @@ public class LocalVmManager {
5253
* has appropriate permissions.
5354
*/
5455
public LocalVmManager() {
55-
// The files are in {tmpdir}/hsperfdata_{any_user_name}/[0-9]+
56+
// 1.4.2 and later: The files are in {tmpdir}/hsperfdata_{any_user_name}/[0-9]+
5657
Pattern userDirPattern = Pattern.compile(PerfDataFile.userDirNamePattern);
5758
userDirFilter = new FilenameFilter() {
5859
public boolean accept(File dir, String name) {
@@ -66,6 +67,15 @@ public boolean accept(File dir, String name) {
6667
return userDirFilePattern.matcher(name).matches();
6768
}
6869
};
70+
71+
// 1.4.1 (or earlier?): the files are stored directly under {tmpdir}/ with
72+
// the following pattern.
73+
Pattern oldtmpFilePattern = Pattern.compile(PerfDataFile.tmpFileNamePattern);
74+
oldtmpFileFilter = new FilenameFilter() {
75+
public boolean accept(File dir, String name) {
76+
return oldtmpFilePattern.matcher(name).matches();
77+
}
78+
};
6979
}
7080

7181
/**
@@ -90,7 +100,7 @@ public synchronized Set<Integer> activeVms() {
90100
}
91101

92102

93-
// Look for the files {tmpdir}/hsperfdata_{any_user_name}/[0-9]+
103+
// 1.4.2 and later: Look for the files {tmpdir}/hsperfdata_{any_user_name}/[0-9]+
94104
// that are readable by the current user.
95105
File[] dirs = tmpdir.listFiles(userDirFilter);
96106
for (File subDir : dirs) {
@@ -111,6 +121,20 @@ public synchronized Set<Integer> activeVms() {
111121
}
112122
}
113123
}
124+
125+
// look for any 1.4.1 files that are readable by the current user.
126+
File[] files = tmpdir.listFiles(oldtmpFileFilter);
127+
if (files != null) {
128+
for (File file : files) {
129+
if (file.isFile() && file.canRead()) {
130+
int vmid = PerfDataFile.getLocalVmId(file);
131+
if (vmid != -1) {
132+
jvmSet.add(vmid);
133+
}
134+
}
135+
}
136+
}
137+
114138
}
115139
return jvmSet;
116140
}

src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataBuffer.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,33 @@ public class PerfDataBuffer extends AbstractPerfDataBuffer {
6161
*/
6262
public PerfDataBuffer(VmIdentifier vmid) throws MonitorException {
6363
try {
64+
// Try 1.4.2 and later first
6465
ByteBuffer bb = perf.attach(vmid.getLocalVmId());
6566
createPerfDataBuffer(bb, vmid.getLocalVmId());
67+
68+
} catch (IllegalArgumentException e) {
69+
// now try 1.4.1 by attempting to directly map the files.
70+
try {
71+
String filename = PerfDataFile.getTempDirectory()
72+
+ PerfDataFile.dirNamePrefix
73+
+ Integer.toString(vmid.getLocalVmId());
74+
75+
File f = new File(filename);
76+
77+
FileChannel fc = new RandomAccessFile(f, "r").getChannel();
78+
ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0L,
79+
(int)fc.size());
80+
fc.close();
81+
createPerfDataBuffer(bb, vmid.getLocalVmId());
82+
83+
} catch (FileNotFoundException e2) {
84+
// re-throw the exception from the 1.4.2 attach method
85+
throw new MonitorException(vmid.getLocalVmId() + " not found",
86+
e);
87+
} catch (IOException e2) {
88+
throw new MonitorException("Could not map 1.4.1 file for "
89+
+ vmid.getLocalVmId(), e2);
90+
}
6691
} catch (IOException e) {
6792
throw new MonitorException("Could not attach to "
6893
+ vmid.getLocalVmId(), e);

src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataFile.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -64,11 +64,20 @@ public class PerfDataFile {
6464
* The file name pattern for PerfData shared memory files.
6565
* <p>
6666
* This pattern must be kept in synch with the file name pattern
67-
* used by the 1.4.2 and later HotSpot JVM. Earlier versions are
68-
* no longer supported.
67+
* used by the 1.4.2 and later HotSpot JVM.
6968
*/
7069
public static final String fileNamePattern = "^[0-9]+$";
7170

71+
/**
72+
* The file name pattern for 1.4.1 PerfData shared memory files.
73+
* <p>
74+
* This pattern must be kept in synch with the file name pattern
75+
* used by the 1.4.1 HotSpot JVM.
76+
*/
77+
public static final String tmpFileNamePattern =
78+
"^hsperfdata_[0-9]+(_[1-2]+)?$";
79+
80+
7281
/**
7382
* Platform Specific methods for looking up temporary directories
7483
* and process IDs.
@@ -88,10 +97,24 @@ public class PerfDataFile {
8897
*/
8998
public static int getLocalVmId(File file) {
9099
try {
100+
// try 1.4.2 and later format first
91101
return(platSupport.getLocalVmId(file));
92102
} catch (NumberFormatException e) { }
93103

94-
throw new IllegalArgumentException("Cannot convert '" + file + "' to VM id");
104+
// now try the 1.4.1 format
105+
String name = file.getName();
106+
if (name.startsWith(dirNamePrefix)) {
107+
int first = name.indexOf('_');
108+
int last = name.lastIndexOf('_');
109+
try {
110+
if (first == last) {
111+
return Integer.parseInt(name.substring(first + 1));
112+
} else {
113+
return Integer.parseInt(name.substring(first + 1, last));
114+
}
115+
} catch (NumberFormatException e) { }
116+
}
117+
throw new IllegalArgumentException("file name does not match pattern");
95118
}
96119

97120
/**

0 commit comments

Comments
 (0)