# HG changeset patch # User jbachorik # Date 1427214088 0 # Node ID ea1dbf32c8659d37c9d52ce8c878592d55ab9349 # Parent 20d4dc1409a63342e514ac3acdedfa560da56fc2# Parent fbba8c368ce0d11104b0176e3457725d133eb25c Merge diff -r 20d4dc1409a6 -r ea1dbf32c865 hotspot/test/serviceability/attach/AttachWithStalePidFile.java --- a/hotspot/test/serviceability/attach/AttachWithStalePidFile.java Mon Mar 23 13:53:44 2015 +0100 +++ b/hotspot/test/serviceability/attach/AttachWithStalePidFile.java Tue Mar 24 16:21:28 2015 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -26,7 +26,6 @@ * @bug 7162400 * @key regression * @summary Regression test for attach issue where stale pid files in /tmp lead to connection issues - * @ignore 8024055 * @library /testlibrary * @build com.oracle.java.testlibrary.* AttachWithStalePidFileTarget * @run main AttachWithStalePidFile @@ -79,9 +78,7 @@ // wait for vm.paused file to be created and delete it once we find it. waitForAndResumeVM(pid); - // unfortunately there's no reliable way to know the VM is ready to receive the - // attach request so we have to do an arbitrary sleep. - Thread.sleep(5000); + waitForTargetReady(target); HotSpotVirtualMachine vm = (HotSpotVirtualMachine)VirtualMachine.attach(((Integer)pid).toString()); BufferedReader remoteDataReader = new BufferedReader(new InputStreamReader(vm.remoteDataDump())); @@ -101,6 +98,16 @@ } } + private static void waitForTargetReady(Process target) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(target.getInputStream())); + String line = br.readLine(); + // wait for the ready message having been printed or EOF (line == null) + while (line != null && !line.equals(AttachWithStalePidFileTarget.READY_MSG)) { + line = br.readLine(); + } + // target VM ready + } + private static Path createJavaPidFile(int pid) throws Exception { Path pidFile = Paths.get("/tmp/.java_pid" + pid); if(Files.exists(pidFile)) { @@ -108,8 +115,10 @@ Files.delete(pidFile); } catch(FileSystemException e) { - if(e.getReason().equals("Operation not permitted")) { + if(e.getReason().matches("Operation not permitted|Not owner")) { System.out.println("Unable to remove exisiting stale PID file" + pidFile); + System.out.println("==================================================="); + e.printStackTrace(System.out); return null; } throw e; diff -r 20d4dc1409a6 -r ea1dbf32c865 hotspot/test/serviceability/attach/AttachWithStalePidFileTarget.java --- a/hotspot/test/serviceability/attach/AttachWithStalePidFileTarget.java Mon Mar 23 13:53:44 2015 +0100 +++ b/hotspot/test/serviceability/attach/AttachWithStalePidFileTarget.java Tue Mar 24 16:21:28 2015 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -21,7 +21,10 @@ * questions. */ public class AttachWithStalePidFileTarget { + static final String READY_MSG = "*ready*"; public static void main(String... args) throws Exception { - Thread.sleep(2*60*1000); + System.out.println(READY_MSG); + System.out.flush(); + System.in.read(); } }