attila@963: /* attila@963: * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. attila@963: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@963: * attila@963: * This code is free software; you can redistribute it and/or modify it attila@963: * under the terms of the GNU General Public License version 2 only, as attila@963: * published by the Free Software Foundation. attila@963: * attila@963: * This code is distributed in the hope that it will be useful, but WITHOUT attila@963: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or attila@963: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License attila@963: * version 2 for more details (a copy is included in the LICENSE file that attila@963: * accompanied this code). attila@963: * attila@963: * You should have received a copy of the GNU General Public License version attila@963: * 2 along with this work; if not, write to the Free Software Foundation, attila@963: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@963: * attila@963: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA attila@963: * or visit www.oracle.com if you need additional information or have any attila@963: * questions. attila@963: */ attila@963: attila@963: /** attila@963: * Debug.eventqueue test - instead of screen scraping, test the concept of asking Debug for attila@963: * an event log of favourable events. attila@963: * attila@963: * @test attila@963: * @fork attila@963: * @option -Dnashorn.debug=true attila@963: * @option --log=recompile:quiet attila@963: * @option --optimistic-types=true attila@963: */ attila@963: attila@963: print(Debug); attila@963: print(); attila@963: attila@963: var forName = java.lang.Class["forName(String)"]; attila@963: var RuntimeEvent = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static; attila@963: var getValue = RuntimeEvent.class.getMethod("getValue"); attila@963: var getValueClass = RuntimeEvent.class.getMethod("getValueClass"); attila@963: attila@963: print(RuntimeEvent); attila@963: attila@963: var RewriteException = forName("jdk.nashorn.internal.runtime.RewriteException").static; attila@963: var getReturnType = RewriteException.class.getMethod("getReturnType"); attila@963: attila@963: print(RewriteException); attila@963: attila@963: var a = [1.1, 2.2]; attila@963: function f() { attila@963: var sum = 2; attila@963: for (var i = 0; i < a.length; i++) { attila@963: sum *= a[i]; attila@963: } attila@963: return sum; attila@963: } attila@963: attila@963: function g() { attila@963: var diff = 17; attila@963: for (var i = 0; i < a.length; i++) { attila@963: diff -= a[i]; attila@963: } attila@963: return diff; attila@963: } attila@963: attila@963: //kill anything that may already be in the event queue from earlier debug runs attila@963: Debug.clearRuntimeEvents(); attila@963: attila@963: print(); attila@963: print(f()); attila@963: print(g()); attila@963: attila@963: print(); attila@963: events = Debug.getRuntimeEvents(); attila@963: print("Done with " + events.length + " in the event queue"); attila@963: //make sure we got runtime events attila@963: print("events = " + (events.toString().indexOf("RuntimeEvent") != -1)); attila@963: print("events.length = " + events.length); attila@963: attila@963: var lastInLoop = undefined; attila@963: for (var i = 0; i < events.length; i++) { attila@963: var e = events[i]; attila@963: print("event #" + i); attila@963: print("\tevent class=" + e.getClass()); attila@963: print("\tvalueClass in event=" + getValueClass.invoke(e)); attila@963: var v = getValue.invoke(e); attila@963: print("\tclass of value=" + v.getClass()); attila@963: print("\treturn type=" + getReturnType.invoke(v)); attila@963: lastInLoop = events[i]; attila@963: } attila@963: attila@963: print(); attila@963: print("in loop last class = " + lastInLoop.getClass()); attila@963: print("in loop last value class = " + getValueClass.invoke(lastInLoop)); attila@963: var rexInLoop = getValue.invoke(lastInLoop); attila@963: print("in loop rex class = " + rexInLoop.getClass()); attila@963: print("in loop rex return type = " + getReturnType.invoke(rexInLoop)); attila@963: attila@963: //try last runtime events attila@963: var last = Debug.getLastRuntimeEvent(); attila@963: //the code after the loop creates additional rewrite exceptions attila@963: print(); attila@963: print(last !== lastInLoop); attila@963: print(); attila@963: attila@963: print("last class = " + last.getClass()); attila@963: print("last value class = " + getValueClass.invoke(last)); attila@963: var rex = getValue.invoke(last); attila@963: print("rex class = " + rex.getClass()); attila@963: print("rex return type = " + getReturnType.invoke(rex)); attila@963: attila@963: //try the capacity setter attila@963: print(); attila@963: print(Debug.getEventQueueCapacity()); attila@963: Debug.setEventQueueCapacity(2048); attila@963: print(Debug.getEventQueueCapacity()); attila@963: attila@963: //try clear events attila@963: print(); attila@963: Debug.clearRuntimeEvents(); attila@963: print(Debug.getRuntimeEvents().length); attila@963: