src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataFile.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataFile.java Thu Jan 11 13:32:23 2018
--- new/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataFile.java Thu Jan 11 13:32:23 2018
*** 1,7 ****
--- 1,7 ----
/*
! * Copyright (c) 2004, 2018 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 92,102 ****
--- 92,102 ----
*
* @param lvmid the local Java Virtual Machine Identifier for the target
* @return File - a File object to the backing store file for the named
* shared memory region of the target JVM.
* @see java.io.File
! * @see #getTempDirectory()
! * @see #getTempDirectories()
*/
public static File getFile(int lvmid) {
if (lvmid == 0) {
/*
* lvmid == 0 is used to indicate the current Java Virtual Machine.
*** 105,119 ****
--- 105,123 ----
* identifier. In absence of such an api, return null.
*/
return null;
}
+ String tmpDirs[] = getTempDirectories(null, lvmid);
+ File newest = null;
+
+ for (int t = 0; t < tmpDirs.length; t++) {
/*
* iterate over all files in all directories in tmpDirName that
* match the file name patterns.
*/
! File tmpDir = new File(tmpDirName);
! File tmpDir = new File(tmpDirs[t]);
String[] files = tmpDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
if (!name.startsWith(dirNamePrefix)) {
return false;
}
*** 122,146 ****
--- 126,155 ----
&& candidate.canRead());
}
});
long newestTime = 0;
File newest = null;
for (int i = 0; i < files.length; i++) {
! File f = new File(tmpDirName + files[i]);
! File f = new File(tmpDirs[t] + files[i]);
File candidate = null;
if (f.exists() && f.isDirectory()) {
/*
* found a directory matching the name patterns. This
* is a 1.4.2 hsperfdata_<user> directory. Check for
* file named <lvmid> in that directory
*/
String name = Integer.toString(lvmid);
! candidate = new File(f.getName(), name);
+ String name = f.getAbsolutePath() + File.separator +
! Integer.toString(lvmid);
+ candidate = new File(name);
+ // Try NameSpace Id if Host Id doesn't exist.
+ if (!candidate.exists()) {
+ name = f.getAbsolutePath() + File.separator +
+ Integer.toString(VMSupport.getNamespaceVmId(lvmid));
+ candidate = new File(name);
+ }
} else if (f.exists() && f.isFile()) {
/*
* found a file matching the name patterns. This
* is a 1.4.1 hsperfdata_<lvmid> file.
*/
*** 158,167 ****
--- 167,177 ----
newestTime = modTime;
newest = candidate;
}
}
}
+ }
return newest;
}
/**
* Return the File object for the backing store file for the specified Java
*** 175,185 ****
--- 185,195 ----
* @param user the user name
* @param lvmid the local Java Virtual Machine Identifier for the target
* @return File - a File object to the backing store file for the named
* shared memory region of the target JVM.
* @see java.io.File
! * @see #getTempDirectory()
! * @see #getTempDirectories()
*/
public static File getFile(String user, int lvmid) {
if (lvmid == 0) {
/*
* lvmid == 0 is used to indicate the current Java Virtual Machine.
*** 189,204 ****
--- 199,225 ----
*/
return null;
}
// first try for 1.4.2 and later JVMs
! String basename = getTempDirectory(user) + Integer.toString(lvmid);
! File f = new File(basename);
! String tmpDirs[] = getTempDirectories(user, lvmid);
! String basename;
+ File f;
+ for (int t = 0; t < tmpDirs.length; t++) {
+ basename = tmpDirs[t] + Integer.toString(lvmid);
+ f = new File(basename);
+ if (f.exists() && f.isFile() && f.canRead()) {
+ return f;
+ }
+ // Try NameSpace Id if Host Id doesn't exist.
+ basename = tmpDirs[t] + Integer.toString(VMSupport.getNamespaceVmId(lvmid));
+ f = new File(basename);
if (f.exists() && f.isFile() && f.canRead()) {
return f;
}
+ }
// No hit on 1.4.2 JVMs, try 1.4.1 files
long newestTime = 0;
File newest = null;
for (int i = 0; i < 2; i++) {
*** 234,244 ****
--- 255,265 ----
* does not conform to the expected pattern
*/
public static int getLocalVmId(File file) {
try {
// try 1.4.2 and later format first
! return Integer.parseInt(file.getName());
! return(VMSupport.getLocalVmId(file));
} catch (NumberFormatException e) { }
// now try the 1.4.1 format
String name = file.getName();
if (name.startsWith(dirNamePrefix)) {
*** 284,293 ****
--- 305,336 ----
*/
public static String getTempDirectory(String user) {
return tmpDirName + dirNamePrefix + user + File.separator;
}
+ /**
+ * Return the names of the temporary directories being searched for
+ * HotSpot PerfData backing store files.
+ * <p>
+ * This method returns the traditional host temp directory but also
+ * includes a list of temp directories used by containers.
+ *
+ * @return String[] - A String array of temporary directories to search.
+ */
+ public static String[] getTempDirectories(String userName, int vmid) {
+ String[] list = VMSupport.getVMTemporaryDirectories(vmid);
+ if (userName == null) {
+ return list;
+ }
+
+ String[] nameList = new String[list.length];
+ for (int i = 0; i < list.length; i++) {
+ nameList[i] = new String(list[i] + dirNamePrefix + userName + File.separator);
+ }
+ return nameList;
+ }
+
static {
/*
* For this to work, the target VM and this code need to use
* the same directory. Instead of guessing which directory the
* VM is using, we will ask.
src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataFile.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File