1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/trusted/event_queue.js Wed Aug 20 10:26:01 2014 +0200 1.3 @@ -0,0 +1,123 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * Debug.eventqueue test - instead of screen scraping, test the concept of asking Debug for 1.29 + * an event log of favourable events. 1.30 + * 1.31 + * @test 1.32 + * @fork 1.33 + * @option -Dnashorn.debug=true 1.34 + * @option --log=recompile:quiet 1.35 + * @option --optimistic-types=true 1.36 + */ 1.37 + 1.38 +print(Debug); 1.39 +print(); 1.40 + 1.41 +var forName = java.lang.Class["forName(String)"]; 1.42 +var RuntimeEvent = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static; 1.43 +var getValue = RuntimeEvent.class.getMethod("getValue"); 1.44 +var getValueClass = RuntimeEvent.class.getMethod("getValueClass"); 1.45 + 1.46 +print(RuntimeEvent); 1.47 + 1.48 +var RewriteException = forName("jdk.nashorn.internal.runtime.RewriteException").static; 1.49 +var getReturnType = RewriteException.class.getMethod("getReturnType"); 1.50 + 1.51 +print(RewriteException); 1.52 + 1.53 +var a = [1.1, 2.2]; 1.54 +function f() { 1.55 + var sum = 2; 1.56 + for (var i = 0; i < a.length; i++) { 1.57 + sum *= a[i]; 1.58 + } 1.59 + return sum; 1.60 +} 1.61 + 1.62 +function g() { 1.63 + var diff = 17; 1.64 + for (var i = 0; i < a.length; i++) { 1.65 + diff -= a[i]; 1.66 + } 1.67 + return diff; 1.68 +} 1.69 + 1.70 +//kill anything that may already be in the event queue from earlier debug runs 1.71 +Debug.clearRuntimeEvents(); 1.72 + 1.73 +print(); 1.74 +print(f()); 1.75 +print(g()); 1.76 + 1.77 +print(); 1.78 +events = Debug.getRuntimeEvents(); 1.79 +print("Done with " + events.length + " in the event queue"); 1.80 +//make sure we got runtime events 1.81 +print("events = " + (events.toString().indexOf("RuntimeEvent") != -1)); 1.82 +print("events.length = " + events.length); 1.83 + 1.84 +var lastInLoop = undefined; 1.85 +for (var i = 0; i < events.length; i++) { 1.86 + var e = events[i]; 1.87 + print("event #" + i); 1.88 + print("\tevent class=" + e.getClass()); 1.89 + print("\tvalueClass in event=" + getValueClass.invoke(e)); 1.90 + var v = getValue.invoke(e); 1.91 + print("\tclass of value=" + v.getClass()); 1.92 + print("\treturn type=" + getReturnType.invoke(v)); 1.93 + lastInLoop = events[i]; 1.94 +} 1.95 + 1.96 +print(); 1.97 +print("in loop last class = " + lastInLoop.getClass()); 1.98 +print("in loop last value class = " + getValueClass.invoke(lastInLoop)); 1.99 +var rexInLoop = getValue.invoke(lastInLoop); 1.100 +print("in loop rex class = " + rexInLoop.getClass()); 1.101 +print("in loop rex return type = " + getReturnType.invoke(rexInLoop)); 1.102 + 1.103 +//try last runtime events 1.104 +var last = Debug.getLastRuntimeEvent(); 1.105 +//the code after the loop creates additional rewrite exceptions 1.106 +print(); 1.107 +print(last !== lastInLoop); 1.108 +print(); 1.109 + 1.110 +print("last class = " + last.getClass()); 1.111 +print("last value class = " + getValueClass.invoke(last)); 1.112 +var rex = getValue.invoke(last); 1.113 +print("rex class = " + rex.getClass()); 1.114 +print("rex return type = " + getReturnType.invoke(rex)); 1.115 + 1.116 +//try the capacity setter 1.117 +print(); 1.118 +print(Debug.getEventQueueCapacity()); 1.119 +Debug.setEventQueueCapacity(2048); 1.120 +print(Debug.getEventQueueCapacity()); 1.121 + 1.122 +//try clear events 1.123 +print(); 1.124 +Debug.clearRuntimeEvents(); 1.125 +print(Debug.getRuntimeEvents().length); 1.126 +