1 /* |
1 /* |
2 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
49 Class<?> managerClass = Class.forName("javax.script.ScriptEngineManager"); |
49 Class<?> managerClass = Class.forName("javax.script.ScriptEngineManager"); |
50 Object manager = managerClass.newInstance(); |
50 Object manager = managerClass.newInstance(); |
51 |
51 |
52 // create JavaScript engine |
52 // create JavaScript engine |
53 Method getEngineMethod = managerClass.getMethod("getEngineByName", |
53 Method getEngineMethod = managerClass.getMethod("getEngineByName", |
54 new Class[] { String.class }); |
54 new Class<?>[] { String.class }); |
55 Object jse = getEngineMethod.invoke(manager, new Object[] {"js"}); |
55 Object jse = getEngineMethod.invoke(manager, new Object[] {"js"}); |
56 oqlSupported = (jse != null); |
56 oqlSupported = (jse != null); |
57 } catch (Exception exp) { |
57 } catch (Exception exp) { |
58 oqlSupported = false; |
58 oqlSupported = false; |
59 } |
59 } |
203 if (whereCode != null) { |
203 if (whereCode != null) { |
204 evalMethod.invoke(engine, new Object[] { whereCode }); |
204 evalMethod.invoke(engine, new Object[] { whereCode }); |
205 } |
205 } |
206 |
206 |
207 if (q.className != null) { |
207 if (q.className != null) { |
208 Enumeration objects = clazz.getInstances(q.isInstanceOf); |
208 Enumeration<JavaHeapObject> objects = clazz.getInstances(q.isInstanceOf); |
209 while (objects.hasMoreElements()) { |
209 while (objects.hasMoreElements()) { |
210 JavaHeapObject obj = (JavaHeapObject) objects.nextElement(); |
210 JavaHeapObject obj = objects.nextElement(); |
211 Object[] args = new Object[] { wrapJavaObject(obj) }; |
211 Object[] args = new Object[] { wrapJavaObject(obj) }; |
212 boolean b = (whereCode == null); |
212 boolean b = (whereCode == null); |
213 if (!b) { |
213 if (!b) { |
214 Object res = call("__where__", args); |
214 Object res = call("__where__", args); |
215 if (res instanceof Boolean) { |
215 if (res instanceof Boolean) { |
263 Class<?> managerClass = Class.forName("javax.script.ScriptEngineManager"); |
263 Class<?> managerClass = Class.forName("javax.script.ScriptEngineManager"); |
264 Object manager = managerClass.newInstance(); |
264 Object manager = managerClass.newInstance(); |
265 |
265 |
266 // create JavaScript engine |
266 // create JavaScript engine |
267 Method getEngineMethod = managerClass.getMethod("getEngineByName", |
267 Method getEngineMethod = managerClass.getMethod("getEngineByName", |
268 new Class[] { String.class }); |
268 new Class<?>[] { String.class }); |
269 engine = getEngineMethod.invoke(manager, new Object[] {"js"}); |
269 engine = getEngineMethod.invoke(manager, new Object[] {"js"}); |
270 |
270 |
271 // initialize engine with init file (hat.js) |
271 // initialize engine with init file (hat.js) |
272 InputStream strm = getInitStream(); |
272 InputStream strm = getInitStream(); |
273 Class<?> engineClass = Class.forName("javax.script.ScriptEngine"); |
273 Class<?> engineClass = Class.forName("javax.script.ScriptEngine"); |
274 evalMethod = engineClass.getMethod("eval", |
274 evalMethod = engineClass.getMethod("eval", |
275 new Class[] { Reader.class }); |
275 new Class<?>[] { Reader.class }); |
276 evalMethod.invoke(engine, new Object[] {new InputStreamReader(strm)}); |
276 evalMethod.invoke(engine, new Object[] {new InputStreamReader(strm)}); |
277 |
277 |
278 // initialize ScriptEngine.eval(String) and |
278 // initialize ScriptEngine.eval(String) and |
279 // Invocable.invokeFunction(String, Object[]) methods. |
279 // Invocable.invokeFunction(String, Object[]) methods. |
280 Class<?> invocableClass = Class.forName("javax.script.Invocable"); |
280 Class<?> invocableClass = Class.forName("javax.script.Invocable"); |
281 |
281 |
282 evalMethod = engineClass.getMethod("eval", |
282 evalMethod = engineClass.getMethod("eval", |
283 new Class[] { String.class }); |
283 new Class<?>[] { String.class }); |
284 invokeMethod = invocableClass.getMethod("invokeFunction", |
284 invokeMethod = invocableClass.getMethod("invokeFunction", |
285 new Class[] { String.class, Object[].class }); |
285 new Class<?>[] { String.class, Object[].class }); |
286 |
286 |
287 // initialize ScriptEngine.put(String, Object) method |
287 // initialize ScriptEngine.put(String, Object) method |
288 Method putMethod = engineClass.getMethod("put", |
288 Method putMethod = engineClass.getMethod("put", |
289 new Class[] { String.class, Object.class }); |
289 new Class<?>[] { String.class, Object.class }); |
290 |
290 |
291 // call ScriptEngine.put to initialize built-in heap object |
291 // call ScriptEngine.put to initialize built-in heap object |
292 putMethod.invoke(engine, new Object[] { |
292 putMethod.invoke(engine, new Object[] { |
293 "heap", call("wrapHeapSnapshot", new Object[] { snapshot }) |
293 "heap", call("wrapHeapSnapshot", new Object[] { snapshot }) |
294 }); |
294 }); |