7051182: Regression: : jconsole scripting demo fails with UndeclaredThrowableException

Andreas Rieber rieberandreas at gmail.com
Wed May 29 04:34:47 PDT 2013


Hi Sundar,

it is all in the same repro (jdk demo) but the fix (public class... in 
ScriptShellPanel.java) would not work without the changes required for 
Nashorn. So i guess one patch is fine and shorter this time.

Andreas



On 29.05.13 11:36, A. Sundararajan wrote:
> Hi Andreas,
>
> If changes are across repos (nashorn, jdk/demo) it is better to have 
> two patches. But, you could zip everything and send as well.
>
> Thanks
> -Sundar
>
> On Wednesday 29 May 2013 12:01 PM, Andreas Rieber wrote:
>> Hi,
>>
>> i have a one line fix for this bug but i also have a patch to make 
>> jconsole-plugin demo working with Nashorn. The problems there are 
>> similar to scriptpad (sync function, array handling and the new 
>> JSAdapter __call__).
>>
>> Do you want two separate patches or is one OK?
>>
>> cheers
>> Andreas
>>
>

-------------- next part --------------
diff --git a/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptJConsolePlugin.java b/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptJConsolePlugin.java
--- a/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptJConsolePlugin.java
+++ b/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptJConsolePlugin.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -148,10 +148,11 @@
     private String getScriptLanguage() {
         // check whether explicit System property is set
         String lang = System.getProperty(LANGUAGE_KEY);
+
         if (lang == null) {
-            // default is JavaScript
-            lang = "JavaScript";
+            lang = "nashorn";
         }
+
         return lang;
     }
 
diff --git a/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptShellPanel.java b/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptShellPanel.java
--- a/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptShellPanel.java
+++ b/src/share/demo/scripting/jconsole-plugin/src/com/sun/demo/scripting/jconsole/ScriptShellPanel.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -54,7 +54,7 @@
  * jconsole's script console.
  */
 
-class ScriptShellPanel extends JPanel {
+public class ScriptShellPanel extends JPanel {
 
     private static final long serialVersionUID = 4116273141148726319L;
 
diff --git a/src/share/demo/scripting/jconsole-plugin/src/resources/jconsole.js b/src/share/demo/scripting/jconsole-plugin/src/resources/jconsole.js
--- a/src/share/demo/scripting/jconsole-plugin/src/resources/jconsole.js
+++ b/src/share/demo/scripting/jconsole-plugin/src/resources/jconsole.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -77,12 +77,37 @@
 function jcontext() {
     return plugin.getContext();
 }
-jcontext.docString = "returns JConsoleContext for the current jconsole plugin" 
+jcontext.docString = "returns JConsoleContext for the current jconsole plugin";
 
 function mbeanConnection() {
     return jcontext().getMBeanServerConnection();
 }
-mbeanConnection.docString = "returns current MBeanServer connection"
+mbeanConnection.docString = "returns current MBeanServer connection";
+
+// check if there is a build in sync function, define one if missing
+if (typeof sync === "undefined") {
+    var sync = function(func, obj) {
+        if (arguments.length < 1 || arguments.length > 2 ) {
+            throw "sync(function [,object]) parameter count mismatch";
+        }
+
+        var syncobj = (arguments.length == 2 ? obj : this);
+
+        if (!syncobj._syncLock) {
+            syncobj._syncLock = new Lock();
+        }
+
+        return function() {
+            syncobj._syncLock.lock();
+            try {
+                func.apply(null, arguments);
+            } finally {
+                syncobj._syncLock.unlock();
+            }
+        };
+    };
+    sync.docString = "synchronize a function, optionally on an object";
+}
 
 /**
  * Prints one liner help message for each function exposed here
@@ -188,22 +213,12 @@
 
 // wraps a script array as java.lang.Object[]
 function objectArray(array) {
-    var len = array.length;
-    var res = java.lang.reflect.Array.newInstance(java.lang.Object, len);
-    for (var i = 0; i < array.length; i++) {
-        res[i] = array[i];
-    }
-    return res;
+    return Java.to(array, "java.lang.Object[]");
 }
 
 // wraps a script (string) array as java.lang.String[]
 function stringArray(array) {
-    var len = array.length;
-    var res = java.lang.reflect.Array.newInstance(java.lang.String, len);
-    for (var i = 0; i < array.length; i++) {
-        res[i] = String(array[i]);
-    }
-    return res;
+    return Java.to(array, "java.lang.String[]");
 }
 
 // script array to Java List
@@ -286,16 +301,18 @@
  * will be of type FutureTask. When you need value, call 'get' on it.
  */
 function mbean(objName, async) {
+    var index;
+
     objName = objectName(objName);
     var info = mbeanInfo(objName);
     var attrs = info.attributes;
     var attrMap = new Object;
-    for (var index in attrs) {
+    for (index in attrs) {
         attrMap[attrs[index].name] = attrs[index];
     }
     var opers = info.operations;
     var operMap = new Object;
-    for (var index in opers) {
+    for (index in opers) {
         operMap[opers[index].name] = opers[index];
     }
 
@@ -318,21 +335,30 @@
                 } else {
                     return getMBeanAttribute(objName, name); 
                 }
-            } else if (isOperation(name)) {
+            } else {
+                return undefined;
+            }
+        },
+        __call__: function(name) {
+            if (isOperation(name)) {
                 var oper = operMap[name];
-                return function() {
-                    var params = objectArray(arguments);
-                    var sigs = oper.signature;
-                    var sigNames = new Array(sigs.length);
-                    for (var index in sigs) {
-                        sigNames[index] = sigs[index].getType();
-                    }
-                    if (async) {
-                        return invokeMBean.future(objName, name, 
-                                                  params, sigNames);
-                    } else {
-                        return invokeMBean(objName, name, params, sigNames);
-                    }
+
+                var params = [];
+                for (var j = 1; j < arguments.length; j++) {
+                    params[j-1]= arguments[j];
+                }
+
+                var sigs = oper.signature;
+
+                var sigNames = new Array(sigs.length);
+                for (var index in sigs) {
+                    sigNames[index] = sigs[index].getType();
+                }
+
+                if (async) {
+                    return invokeMBean.future(objName, name, params, sigNames);
+                } else {
+                    return invokeMBean(objName, name, params, sigNames);
                 }
             } else {
                 return undefined;
@@ -520,7 +546,7 @@
     } finally {
         lock.unlock();
     }
-}
+};
 
 /**
  * Causes current thread to sleep for specified
@@ -550,12 +576,16 @@
     // and calls callback in an infinite loop
     return (function() {
          while (true) {
-             sleep(interval);
+             try {
+                 sleep(interval);
+             } catch (x) {
+                 break;
+             }
              callback();
          }
     }).daemon();
 }
-setTimeout.docString = "calls given callback once after specified interval"
+setTimeout.docString = "calls given callback once after specified interval";
 
 /** 
  * Cancels a timeout set earlier.
@@ -680,7 +710,7 @@
         if (msg === undefined) msg = "undefined";
         if (msg === null) msg = "null";
         if (title == undefined) title = msg;
-        if (msgType == undefined) type = JOptionPane.INFORMATION_MESSAGE;
+        if (msgType == undefined) msgType = JOptionPane.INFORMATION_MESSAGE;
         JOptionPane.showMessageDialog(window, msg, title, msgType);
     }
     if (isEventThread()) {
@@ -800,7 +830,7 @@
  * Clear the screen
  */
 function clear() {
-    (function() { window.clear(false) }).invokeLater();
+    (function() { window.clear(false); }).invokeLater();
 }
 clear.docString = "clears interactive console screen";
 
diff --git a/src/share/demo/scripting/jconsole-plugin/src/scripts/jstack.js b/src/share/demo/scripting/jconsole-plugin/src/scripts/jstack.js
--- a/src/share/demo/scripting/jconsole-plugin/src/scripts/jstack.js
+++ b/src/share/demo/scripting/jconsole-plugin/src/scripts/jstack.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -87,7 +87,7 @@
 
     var tmbean = newPlatformMXBeanProxy(
         "java.lang:type=Threading",
-        java.lang.management.ThreadMXBean);
+        java.lang.management.ThreadMXBean.class);
 
     var tids = tmbean.allThreadIds;
     var tinfos = tmbean["getThreadInfo(long[],int)"](tids, maxFrames);
diff --git a/src/share/demo/scripting/jconsole-plugin/src/scripts/jtop.js b/src/share/demo/scripting/jconsole-plugin/src/scripts/jtop.js
--- a/src/share/demo/scripting/jconsole-plugin/src/scripts/jtop.js
+++ b/src/share/demo/scripting/jconsole-plugin/src/scripts/jtop.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,10 +62,10 @@
 function getThreadList() {
     var tmbean = newPlatformMXBeanProxy(
         "java.lang:type=Threading",
-        java.lang.management.ThreadMXBean);
+        java.lang.management.ThreadMXBean.class);
 
     if (!tmbean.isThreadCpuTimeSupported()) {
-        return;
+        return new java.util.ArrayList();
     }
 
     tmbean.setThreadCpuTimeEnabled(true);
diff --git a/src/share/demo/scripting/jconsole-plugin/src/scripts/sysprops.js b/src/share/demo/scripting/jconsole-plugin/src/scripts/sysprops.js
--- a/src/share/demo/scripting/jconsole-plugin/src/scripts/sysprops.js
+++ b/src/share/demo/scripting/jconsole-plugin/src/scripts/sysprops.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,7 +62,7 @@
 function getSystemProps() {
     var runtimeBean = newPlatformMXBeanProxy(
                 "java.lang:type=Runtime",
-                java.lang.management.RuntimeMXBean);
+                java.lang.management.RuntimeMXBean.class);
     return runtimeBean.systemProperties;
 }
 


More information about the nashorn-dev mailing list