From f754e84886accecd2c700d90dd41dfa8caeca4af Mon Sep 17 00:00:00 2001 From: Simon Rushton Date: Wed, 13 Jan 2021 09:40:23 +0000 Subject: [PATCH] Add stack trace print for jlm test connect exceptions Signed-off-by: Simon Rushton --- .../test/jlm/remote/ClassProfiler.java | 44 +++++++++++-------- .../test/jlm/remote/MemoryProfiler.java | 39 ++++++++++------ .../test/jlm/remote/ThreadProfiler.java | 34 ++++++++------ 3 files changed, 72 insertions(+), 45 deletions(-) diff --git a/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ClassProfiler.java b/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ClassProfiler.java index 143d1074..2a2492c4 100644 --- a/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ClassProfiler.java +++ b/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ClassProfiler.java @@ -166,22 +166,23 @@ private void getStatsViaProxy() { ie.printStackTrace(); Assert.fail("The sleeping profiler was interrupted"); } catch (UndeclaredThrowableException ue) { + // If the exception was caused by a Connect or Unmarshal Exception + // assume the monitored JVM has finished. Throwable cause = ue.getCause(); Class connectExcept = ConnectException.class; Class unmarshalExcept = UnmarshalException.class; - - if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) { - - // If the exception was caused by a Connect or Unmarshal - // Exception, assume the monitored JVM has finished. - this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); - Assert.fail("Exiting as JVM we are connected to has finished"); - } else { - Message.logOut(ue.getMessage()); - ue.printStackTrace(); - Assert.fail(ue.getMessage()); + String msg = ""; + if (connectExcept.isInstance(cause)) { + msg = "Exiting as ConnectException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; } + else if (unmarshalExcept.isInstance(cause)) { + msg = "Exiting as UnmarshalException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + } + msg += ue.getMessage(); + this.closeCSVFile(); + Message.logOut(msg); + ue.printStackTrace(); + Assert.fail(msg); } finally { this.closeCSVFile(); } @@ -258,17 +259,22 @@ private void getStatsViaServer() { Thread.sleep(1000); secondsCnt++; } - - // If the exception is a Connect or Unmarshal Exception, assume the - // monitored JVM has finished + // If the exception is a Connect or Unmarshal Exception assume the + // monitored JVM has finished. } catch (ConnectException ce) { this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); - Assert.fail("Exiting as JVM we are connected to has finished"); + String msg = "Exiting as ConnectException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + msg += ce.getMessage(); + Message.logOut(msg); + ce.printStackTrace(); + Assert.fail(msg); } catch (UnmarshalException ue) { this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); - Assert.fail("Exiting as JVM we are connected to has finished"); + String msg = "Exiting as UnmarshalException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + msg += ue.getMessage(); + Message.logOut(msg); + ue.printStackTrace(); + Assert.fail(msg); } catch (InterruptedException ie) { Message.logOut("The sleeping profiler was interrupted"); ie.printStackTrace(); diff --git a/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/MemoryProfiler.java b/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/MemoryProfiler.java index 44f19ab2..f3d70373 100644 --- a/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/MemoryProfiler.java +++ b/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/MemoryProfiler.java @@ -192,20 +192,23 @@ private void getStatsViaProxy() { ie.printStackTrace(); Assert.fail("The sleeping profiler was interrupted"); } catch (UndeclaredThrowableException ue) { - // If the exception was caused by a Connect or Unmarshal Exception, assume the - // monitored JVM has finished. + // If the exception was caused by a Connect or Unmarshal Exception + // assume the monitored JVM has finished. Throwable cause = ue.getCause(); - Class connectExcept = ConnectException.class; - Class unmarshalExcept = UnmarshalException.class; - - if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) { - this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); + Class connectExcept = ConnectException.class; + Class unmarshalExcept = UnmarshalException.class; + String msg = ""; + if (connectExcept.isInstance(cause)) { + msg = "Exiting as ConnectException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; } - else { - Message.logOut("Rethrowing UndeclaredThrowableException"); + else if (unmarshalExcept.isInstance(cause)) { + msg = "Exiting as UnmarshalException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; } - Assert.fail(); + msg += ue.getMessage(); + this.closeCSVFile(); + Message.logOut(msg); + ue.printStackTrace(); + Assert.fail(msg); } finally { this.closeCSVFile(); } @@ -256,12 +259,22 @@ private void getStatsViaServer() { Thread.sleep(1000); secondsCnt++; } + // If the exception is a Connect or Unmarshal Exception assume the + // monitored JVM has finished. } catch (ConnectException ce) { this.closeCSVFile(); - Assert.fail("Exiting as JVM we are connected to has finished"); + String msg = "Exiting as ConnectException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + msg += ce.getMessage(); + Message.logOut(msg); + ce.printStackTrace(); + Assert.fail(msg); } catch (UnmarshalException ue) { this.closeCSVFile(); - Assert.fail("Exiting as JVM we are connected to has finished"); + String msg = "Exiting as UnmarshalException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + msg += ue.getMessage(); + Message.logOut(msg); + ue.printStackTrace(); + Assert.fail(msg); } catch (InterruptedException ie) { ie.printStackTrace(); Assert.fail("The sleeping profiler was interrupted"); diff --git a/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ThreadProfiler.java b/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ThreadProfiler.java index 451a4487..1fb5856c 100644 --- a/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ThreadProfiler.java +++ b/openjdk.test.jlm/src/test.jlm/net/adoptopenjdk/test/jlm/remote/ThreadProfiler.java @@ -150,16 +150,18 @@ private void getStatsViaProxy() { Throwable cause = ue.getCause(); Class connectExcept = ConnectException.class; Class unmarshalExcept = UnmarshalException.class; - - if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) { - this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); - Assert.fail("Exiting as JVM we are connected to has finished"); - } else { - Message.logOut(ue.getMessage()); - ue.printStackTrace(); - Assert.fail(ue.getMessage()); + String msg = ""; + if (connectExcept.isInstance(cause)) { + msg = "Exiting as ConnectException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; } + else if (unmarshalExcept.isInstance(cause)) { + msg = "Exiting as UnmarshalException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + } + msg += ue.getMessage(); + this.closeCSVFile(); + Message.logOut(msg); + ue.printStackTrace(); + Assert.fail(msg); } finally { this.closeCSVFile(); } @@ -207,12 +209,18 @@ private void getStatsViaServer() { // monitored JVM has finished. } catch (ConnectException ce) { this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); - Assert.fail("Exiting as JVM we are connected to has finished"); + String msg = "Exiting as ConnectException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + msg += ce.getMessage(); + Message.logOut(msg); + ce.printStackTrace(); + Assert.fail(msg); } catch (UnmarshalException ue) { this.closeCSVFile(); - Message.logOut("Exiting as JVM we are connected to has finished"); - Assert.fail("Exiting as JVM we are connected to has finished"); + String msg = "Exiting as UnmarshalException thrown receiving data from the connected JVM. This may mean the JVM we are connected to has finished. "; + msg += ue.getMessage(); + Message.logOut(msg); + ue.printStackTrace(); + Assert.fail(msg); } catch (InterruptedException ie) { Message.logOut("The sleeping profiler was interrupted"); ie.printStackTrace();