216 newestTime = modTime;
217 newest = f;
218 }
219 }
220 }
221 return newest;
222 }
223
224 /**
225 * Method to extract a local Java Virtual Machine Identifier from the
226 * file name of the given File object.
227 *
228 * @param file A File object representing the name of a
229 * shared memory region for a target JVM
230 * @return int - the local Java Virtual Machine Identifier for the target
231 * associated with the file
232 * @throws java.lang.IllegalArgumentException Thrown if the file name
233 * does not conform to the expected pattern
234 */
235 public static int getLocalVmId(File file) {
236 try {
237 // try 1.4.2 and later format first
238 return Integer.parseInt(file.getName());
239 } catch (NumberFormatException e) { }
240
241 // now try the 1.4.1 format
242 String name = file.getName();
243 if (name.startsWith(dirNamePrefix)) {
244 int first = name.indexOf('_');
245 int last = name.lastIndexOf('_');
246 try {
247 if (first == last) {
248 return Integer.parseInt(name.substring(first + 1));
249 } else {
250 return Integer.parseInt(name.substring(first + 1, last));
251 }
252 } catch (NumberFormatException e) { }
253 }
254 throw new IllegalArgumentException("file name does not match pattern");
255 }
268 public static String getTempDirectory() {
269 return tmpDirName;
270 }
271
272 /**
273 * Return the name of the temporary directory to be searched
274 * for HotSpot PerfData backing store files for a given user.
275 * <p>
276 * This method generally returns the name of a subdirectory of
277 * the directory indicated in the java.io.tmpdir property. However,
278 * on some platforms it may return a different directory, as the
279 * JVM implementation may store the PerfData backing store files
280 * in a different directory for performance reasons.
281 *
282 * @return String - the name of the temporary directory.
283 */
284 public static String getTempDirectory(String user) {
285 return tmpDirName + dirNamePrefix + user + File.separator;
286 }
287
288 static {
289 /*
290 * For this to work, the target VM and this code need to use
291 * the same directory. Instead of guessing which directory the
292 * VM is using, we will ask.
293 */
294 String tmpdir = sun.misc.VMSupport.getVMTemporaryDirectory();
295
296 /*
297 * Assure that the string returned has a trailing File.separator
298 * character. This check was added because the Linux implementation
299 * changed such that the java.io.tmpdir string no longer terminates
300 * with a File.separator character.
301 */
302 if (tmpdir.lastIndexOf(File.separator) != (tmpdir.length()-1)) {
303 tmpdir = tmpdir + File.separator;
304 }
305 tmpDirName = tmpdir;
306 }
307 }
|
216 newestTime = modTime;
217 newest = f;
218 }
219 }
220 }
221 return newest;
222 }
223
224 /**
225 * Method to extract a local Java Virtual Machine Identifier from the
226 * file name of the given File object.
227 *
228 * @param file A File object representing the name of a
229 * shared memory region for a target JVM
230 * @return int - the local Java Virtual Machine Identifier for the target
231 * associated with the file
232 * @throws java.lang.IllegalArgumentException Thrown if the file name
233 * does not conform to the expected pattern
234 */
235 public static int getLocalVmId(File file) {
236 int lvmid = 0;
237
238 try {
239 // try 1.4.2 and later format first
240 return Integer.parseInt(file.getName());
241 } catch (NumberFormatException e) { }
242
243 // now try the 1.4.1 format
244 String name = file.getName();
245 if (name.startsWith(dirNamePrefix)) {
246 int first = name.indexOf('_');
247 int last = name.lastIndexOf('_');
248 try {
249 if (first == last) {
250 return Integer.parseInt(name.substring(first + 1));
251 } else {
252 return Integer.parseInt(name.substring(first + 1, last));
253 }
254 } catch (NumberFormatException e) { }
255 }
256 throw new IllegalArgumentException("file name does not match pattern");
257 }
270 public static String getTempDirectory() {
271 return tmpDirName;
272 }
273
274 /**
275 * Return the name of the temporary directory to be searched
276 * for HotSpot PerfData backing store files for a given user.
277 * <p>
278 * This method generally returns the name of a subdirectory of
279 * the directory indicated in the java.io.tmpdir property. However,
280 * on some platforms it may return a different directory, as the
281 * JVM implementation may store the PerfData backing store files
282 * in a different directory for performance reasons.
283 *
284 * @return String - the name of the temporary directory.
285 */
286 public static String getTempDirectory(String user) {
287 return tmpDirName + dirNamePrefix + user + File.separator;
288 }
289
290 /*
291 * this static initializer would not be necessary if the
292 * Solaris java.io.tmpdir property were set to /tmp by default
293 */
294 static {
295 /*
296 * Why is java.io.tmpdir on Solaris set to "/var/tmp/" when the
297 * HotSpot JVM os:get_temp_path() method returns "/tmp/"
298 *
299 * Why do Solaris and Windows return a string with a trailing
300 * file separator character where as Linix does not? (this change
301 * seems to have occurred sometime during hopper beta)
302 */
303 String tmpdir = System.getProperty("java.io.tmpdir");
304
305 if (tmpdir.compareTo("/var/tmp/") == 0) {
306 /*
307 * shared memory files are created in /tmp. Interestingly,
308 * java.io.tmpdir is set to "/var/tmp/" on Solaris and Linux,
309 * but os::get_temp_directory() is set to "/tmp/" on these
310 * platforms. the java.io.logging packages also makes reference
311 * to java.io.tmpdir.
312 */
313 tmpdir = "/tmp/";
314 }
315
316 /*
317 * Assure that the string returned has a trailing File.separator
318 * character. This check was added because the Linux implementation
319 * changed such that the java.io.tmpdir string no longer terminates
320 * with a File.separator character.
321 */
322 if (tmpdir.lastIndexOf(File.separator) != (tmpdir.length()-1)) {
323 tmpdir = tmpdir + File.separator;
324 }
325 tmpDirName = tmpdir;
326 }
327 }
|