author | jlahoda |
Tue, 09 May 2017 12:22:15 +0200 | |
changeset 45044 | 7c50549b7744 |
parent 43770 | a321bed02000 |
permissions | -rw-r--r-- |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
1 |
/* |
45044
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
4 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
10 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
15 |
* accompanied this code). |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
16 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
20 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
23 |
* questions. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
24 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
25 |
package jdk.jshell.execution; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
26 |
|
41158
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
27 |
import java.lang.reflect.Array; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
28 |
import java.lang.reflect.Field; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
29 |
import java.lang.reflect.InvocationTargetException; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
30 |
import java.lang.reflect.Method; |
43587
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
31 |
import java.util.stream.IntStream; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
32 |
import jdk.jshell.spi.ExecutionControl; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
33 |
import jdk.jshell.spi.SPIResolutionException; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
34 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
35 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
36 |
* An {@link ExecutionControl} implementation that runs in the current process. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
37 |
* May be used directly, or over a channel with |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
38 |
* {@link Util#forwardExecutionControl(ExecutionControl, java.io.ObjectInput, java.io.ObjectOutput) }. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
39 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
40 |
* @author Robert Field |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
41 |
* @author Jan Lahoda |
43770 | 42 |
* @since 9 |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
43 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
44 |
public class DirectExecutionControl implements ExecutionControl { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
45 |
|
43587
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
46 |
private static final String[] charRep; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
47 |
|
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
48 |
static { |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
49 |
charRep = new String[256]; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
50 |
for (int i = 0; i < charRep.length; ++i) { |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
51 |
charRep[i] = Character.isISOControl(i) |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
52 |
? String.format("\\%03o", i) |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
53 |
: "" + (char) i; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
54 |
} |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
55 |
charRep['\b'] = "\\b"; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
56 |
charRep['\t'] = "\\t"; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
57 |
charRep['\n'] = "\\n"; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
58 |
charRep['\f'] = "\\f"; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
59 |
charRep['\r'] = "\\r"; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
60 |
charRep['\\'] = "\\\\"; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
61 |
} |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
62 |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
63 |
private final LoaderDelegate loaderDelegate; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
64 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
65 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
66 |
* Creates an instance, delegating loader operations to the specified |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
67 |
* delegate. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
68 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
69 |
* @param loaderDelegate the delegate to handle loading classes |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
70 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
71 |
public DirectExecutionControl(LoaderDelegate loaderDelegate) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
72 |
this.loaderDelegate = loaderDelegate; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
73 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
74 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
75 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
76 |
* Create an instance using the default class loading. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
77 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
78 |
public DirectExecutionControl() { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
79 |
this(new DefaultLoaderDelegate()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
80 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
81 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
82 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
83 |
public void load(ClassBytecodes[] cbcs) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
84 |
throws ClassInstallException, NotImplementedException, EngineTerminationException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
85 |
loaderDelegate.load(cbcs); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
86 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
87 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
88 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
89 |
public void redefine(ClassBytecodes[] cbcs) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
90 |
throws ClassInstallException, NotImplementedException, EngineTerminationException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
91 |
throw new NotImplementedException("redefine not supported"); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
92 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
93 |
|
45044
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
94 |
/**Notify that classes have been redefined. |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
95 |
* |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
96 |
* @param cbcs the class name and bytecodes to redefine |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
97 |
* @throws NotImplementedException if not implemented |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
98 |
* @throws EngineTerminationException the execution engine has terminated |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
99 |
*/ |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
100 |
protected void classesRedefined(ClassBytecodes[] cbcs) |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
101 |
throws NotImplementedException, EngineTerminationException { |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
102 |
loaderDelegate.classesRedefined(cbcs); |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
103 |
} |
7c50549b7744
8179531: JShell: fails to provide bytecode for dynamically created lambdas
jlahoda
parents:
43770
diff
changeset
|
104 |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
105 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
106 |
public String invoke(String className, String methodName) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
107 |
throws RunException, InternalException, EngineTerminationException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
108 |
Method doitMethod; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
109 |
try { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
110 |
Class<?> klass = findClass(className); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
111 |
doitMethod = klass.getDeclaredMethod(methodName, new Class<?>[0]); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
112 |
doitMethod.setAccessible(true); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
113 |
} catch (Throwable ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
114 |
throw new InternalException(ex.toString()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
115 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
116 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
117 |
try { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
118 |
clientCodeEnter(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
119 |
String result = invoke(doitMethod); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
120 |
System.out.flush(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
121 |
return result; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
122 |
} catch (RunException | InternalException | EngineTerminationException ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
123 |
throw ex; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
124 |
} catch (SPIResolutionException ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
125 |
return throwConvertedInvocationException(ex); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
126 |
} catch (InvocationTargetException ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
127 |
return throwConvertedInvocationException(ex.getCause()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
128 |
} catch (Throwable ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
129 |
return throwConvertedOtherException(ex); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
130 |
} finally { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
131 |
clientCodeLeave(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
132 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
133 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
134 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
135 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
136 |
public String varValue(String className, String varName) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
137 |
throws RunException, EngineTerminationException, InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
138 |
Object val; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
139 |
try { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
140 |
Class<?> klass = findClass(className); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
141 |
Field var = klass.getDeclaredField(varName); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
142 |
var.setAccessible(true); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
143 |
val = var.get(null); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
144 |
} catch (Throwable ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
145 |
throw new InternalException(ex.toString()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
146 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
147 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
148 |
try { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
149 |
clientCodeEnter(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
150 |
return valueString(val); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
151 |
} catch (Throwable ex) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
152 |
return throwConvertedInvocationException(ex); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
153 |
} finally { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
154 |
clientCodeLeave(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
155 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
156 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
157 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
158 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
159 |
public void addToClasspath(String cp) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
160 |
throws EngineTerminationException, InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
161 |
loaderDelegate.addToClasspath(cp); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
162 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
163 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
164 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
165 |
* {@inheritDoc} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
166 |
* <p> |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
167 |
* Not supported. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
168 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
169 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
170 |
public void stop() |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
171 |
throws EngineTerminationException, InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
172 |
throw new NotImplementedException("stop: Not supported."); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
173 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
174 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
175 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
176 |
public Object extensionCommand(String command, Object arg) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
177 |
throws RunException, EngineTerminationException, InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
178 |
throw new NotImplementedException("Unknown command: " + command); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
179 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
180 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
181 |
@Override |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
182 |
public void close() { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
183 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
184 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
185 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
186 |
* Finds the class with the specified binary name. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
187 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
188 |
* @param name the binary name of the class |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
189 |
* @return the Class Object |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
190 |
* @throws ClassNotFoundException if the class could not be found |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
191 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
192 |
protected Class<?> findClass(String name) throws ClassNotFoundException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
193 |
return loaderDelegate.findClass(name); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
194 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
195 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
196 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
197 |
* Invoke the specified "doit-method", a static method with no parameters. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
198 |
* The {@link DirectExecutionControl#invoke(java.lang.String, java.lang.String) } |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
199 |
* in this class will call this to invoke. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
200 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
201 |
* @param doitMethod the Method to invoke |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
202 |
* @return the value or null |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
203 |
* @throws Exception any exceptions thrown by |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
204 |
* {@link java.lang.reflect.Method#invoke(Object, Object...) } |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
205 |
* or any {@link ExecutionControl.ExecutionControlException} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
206 |
* to pass-through. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
207 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
208 |
protected String invoke(Method doitMethod) throws Exception { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
209 |
Object res = doitMethod.invoke(null, new Object[0]); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
210 |
return valueString(res); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
211 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
212 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
213 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
214 |
* Converts the {@code Object} value from |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
215 |
* {@link ExecutionControl#invoke(String, String) } or |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
216 |
* {@link ExecutionControl#varValue(String, String) } to {@code String}. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
217 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
218 |
* @param value the value to convert |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
219 |
* @return the {@code String} representation |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
220 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
221 |
protected static String valueString(Object value) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
222 |
if (value == null) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
223 |
return "null"; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
224 |
} else if (value instanceof String) { |
43587
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
225 |
return "\"" + ((String) value).codePoints() |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
226 |
.flatMap(cp -> |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
227 |
(cp == '"') |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
228 |
? "\\\"".codePoints() |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
229 |
: (cp < 256) |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
230 |
? charRep[cp].codePoints() |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
231 |
: IntStream.of(cp)) |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
232 |
.collect( |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
233 |
StringBuilder::new, |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
234 |
StringBuilder::appendCodePoint, |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
235 |
StringBuilder::append) |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
236 |
.toString() + "\""; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
237 |
} else if (value instanceof Character) { |
43587
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
238 |
char cp = (char) (Character) value; |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
239 |
return "'" + ( |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
240 |
(cp == '\'') |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
241 |
? "\\\'" |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
242 |
: (cp < 256) |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
243 |
? charRep[cp] |
6103af590758
8173807: JShell: control characters should be escaped in String values
rfield
parents:
43132
diff
changeset
|
244 |
: String.valueOf(cp)) + "'"; |
41158
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
245 |
} else if (value.getClass().isArray()) { |
42971
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
246 |
int dims = 0; |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
247 |
Class<?> t = value.getClass(); |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
248 |
while (true) { |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
249 |
Class<?> ct = t.getComponentType(); |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
250 |
if (ct == null) { |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
251 |
break; |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
252 |
} |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
253 |
++dims; |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
254 |
t = ct; |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
255 |
} |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
256 |
String tn = t.getTypeName(); |
41158
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
257 |
int len = Array.getLength(value); |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
258 |
StringBuilder sb = new StringBuilder(); |
42971
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
259 |
sb.append(tn.substring(tn.lastIndexOf('.') + 1, tn.length())); |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
260 |
sb.append("["); |
41158
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
261 |
sb.append(len); |
42971
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
262 |
sb.append("]"); |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
263 |
for (int i = 1; i < dims; ++i) { |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
264 |
sb.append("[]"); |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
265 |
} |
22c8c025a651
8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents:
41158
diff
changeset
|
266 |
sb.append(" { "); |
41158
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
267 |
for (int i = 0; i < len; ++i) { |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
268 |
sb.append(valueString(Array.get(value, i))); |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
269 |
if (i < len - 1) { |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
270 |
sb.append(", "); |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
271 |
} |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
272 |
} |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
273 |
sb.append(" }"); |
957f4fa38bd6
8166400: JShell: friendlier representation of array values
rfield
parents:
39807
diff
changeset
|
274 |
return sb.toString(); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
275 |
} else { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
276 |
return value.toString(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
277 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
278 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
279 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
280 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
281 |
* Converts incoming exceptions in user code into instances of subtypes of |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
282 |
* {@link ExecutionControl.ExecutionControlException} and throws the |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
283 |
* converted exception. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
284 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
285 |
* @param cause the exception to convert |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
286 |
* @return never returns as it always throws |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
287 |
* @throws ExecutionControl.RunException for normal exception occurrences |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
288 |
* @throws ExecutionControl.InternalException for internal problems |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
289 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
290 |
protected String throwConvertedInvocationException(Throwable cause) throws RunException, InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
291 |
if (cause instanceof SPIResolutionException) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
292 |
SPIResolutionException spire = (SPIResolutionException) cause; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
293 |
throw new ResolutionException(spire.id(), spire.getStackTrace()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
294 |
} else { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
295 |
throw new UserException(cause.getMessage(), cause.getClass().getName(), cause.getStackTrace()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
296 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
297 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
298 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
299 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
300 |
* Converts incoming exceptions in agent code into instances of subtypes of |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
301 |
* {@link ExecutionControl.ExecutionControlException} and throws the |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
302 |
* converted exception. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
303 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
304 |
* @param ex the exception to convert |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
305 |
* @return never returns as it always throws |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
306 |
* @throws ExecutionControl.RunException for normal exception occurrences |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
307 |
* @throws ExecutionControl.InternalException for internal problems |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
308 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
309 |
protected String throwConvertedOtherException(Throwable ex) throws RunException, InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
310 |
throw new InternalException(ex.toString()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
311 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
312 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
313 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
314 |
* Marks entry into user code. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
315 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
316 |
* @throws ExecutionControl.InternalException in unexpected failure cases |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
317 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
318 |
protected void clientCodeEnter() throws InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
319 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
320 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
321 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
322 |
* Marks departure from user code. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
323 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
324 |
* @throws ExecutionControl.InternalException in unexpected failure cases |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
325 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
326 |
protected void clientCodeLeave() throws InternalException { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
327 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
328 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
329 |
} |