Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/trusted/event_queue.js
32284 views
/*1* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* Debug.eventqueue test - instead of screen scraping, test the concept of asking Debug for25* an event log of favourable events.26*27* @test28* @fork29* @option -Dnashorn.debug=true30* @option --log=recompile:quiet31* @option --optimistic-types=true32*/3334print(Debug);35print();3637var forName = java.lang.Class["forName(String)"];38var RuntimeEvent = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;39var getValue = RuntimeEvent.class.getMethod("getValue");40var getValueClass = RuntimeEvent.class.getMethod("getValueClass");4142print(RuntimeEvent);4344var RewriteException = forName("jdk.nashorn.internal.runtime.RewriteException").static;45var getReturnType = RewriteException.class.getMethod("getReturnType");4647print(RewriteException);4849var a = [1.1, 2.2];50function f() {51var sum = 2;52for (var i = 0; i < a.length; i++) {53sum *= a[i];54}55return sum;56}5758function g() {59var diff = 17;60for (var i = 0; i < a.length; i++) {61diff -= a[i];62}63return diff;64}6566//kill anything that may already be in the event queue from earlier debug runs67Debug.clearRuntimeEvents();6869print();70print(f());71print(g());7273print();74events = Debug.getRuntimeEvents();75print("Done with " + events.length + " in the event queue");76//make sure we got runtime events77print("events = " + (events.toString().indexOf("RuntimeEvent") != -1));78print("events.length = " + events.length);7980var lastInLoop = undefined;81for (var i = 0; i < events.length; i++) {82var e = events[i];83print("event #" + i);84print("\tevent class=" + e.getClass());85print("\tvalueClass in event=" + getValueClass.invoke(e));86var v = getValue.invoke(e);87print("\tclass of value=" + v.getClass());88print("\treturn type=" + getReturnType.invoke(v));89lastInLoop = events[i];90}9192print();93print("in loop last class = " + lastInLoop.getClass());94print("in loop last value class = " + getValueClass.invoke(lastInLoop));95var rexInLoop = getValue.invoke(lastInLoop);96print("in loop rex class = " + rexInLoop.getClass());97print("in loop rex return type = " + getReturnType.invoke(rexInLoop));9899//try last runtime events100var last = Debug.getLastRuntimeEvent();101//the code after the loop creates additional rewrite exceptions102print();103print(last !== lastInLoop);104print();105106print("last class = " + last.getClass());107print("last value class = " + getValueClass.invoke(last));108var rex = getValue.invoke(last);109print("rex class = " + rex.getClass());110print("rex return type = " + getReturnType.invoke(rex));111112//try the capacity setter113print();114print(Debug.getEventQueueCapacity());115Debug.setEventQueueCapacity(2048);116print(Debug.getEventQueueCapacity());117118//try clear events119print();120Debug.clearRuntimeEvents();121print(Debug.getRuntimeEvents().length);122123124125