test/script/trusted/event_queue.js

Wed, 05 Sep 2018 01:21:35 -0700

author
diazhou
date
Wed, 05 Sep 2018 01:21:35 -0700
changeset 2374
037913b52507
parent 963
e2497b11a021
permissions
-rw-r--r--

Added tag jdk8u192-b09 for changeset 456c0d45c43b

attila@963 1 /*
attila@963 2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
attila@963 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@963 4 *
attila@963 5 * This code is free software; you can redistribute it and/or modify it
attila@963 6 * under the terms of the GNU General Public License version 2 only, as
attila@963 7 * published by the Free Software Foundation.
attila@963 8 *
attila@963 9 * This code is distributed in the hope that it will be useful, but WITHOUT
attila@963 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
attila@963 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
attila@963 12 * version 2 for more details (a copy is included in the LICENSE file that
attila@963 13 * accompanied this code).
attila@963 14 *
attila@963 15 * You should have received a copy of the GNU General Public License version
attila@963 16 * 2 along with this work; if not, write to the Free Software Foundation,
attila@963 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@963 18 *
attila@963 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
attila@963 20 * or visit www.oracle.com if you need additional information or have any
attila@963 21 * questions.
attila@963 22 */
attila@963 23
attila@963 24 /**
attila@963 25 * Debug.eventqueue test - instead of screen scraping, test the concept of asking Debug for
attila@963 26 * an event log of favourable events.
attila@963 27 *
attila@963 28 * @test
attila@963 29 * @fork
attila@963 30 * @option -Dnashorn.debug=true
attila@963 31 * @option --log=recompile:quiet
attila@963 32 * @option --optimistic-types=true
attila@963 33 */
attila@963 34
attila@963 35 print(Debug);
attila@963 36 print();
attila@963 37
attila@963 38 var forName = java.lang.Class["forName(String)"];
attila@963 39 var RuntimeEvent = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;
attila@963 40 var getValue = RuntimeEvent.class.getMethod("getValue");
attila@963 41 var getValueClass = RuntimeEvent.class.getMethod("getValueClass");
attila@963 42
attila@963 43 print(RuntimeEvent);
attila@963 44
attila@963 45 var RewriteException = forName("jdk.nashorn.internal.runtime.RewriteException").static;
attila@963 46 var getReturnType = RewriteException.class.getMethod("getReturnType");
attila@963 47
attila@963 48 print(RewriteException);
attila@963 49
attila@963 50 var a = [1.1, 2.2];
attila@963 51 function f() {
attila@963 52 var sum = 2;
attila@963 53 for (var i = 0; i < a.length; i++) {
attila@963 54 sum *= a[i];
attila@963 55 }
attila@963 56 return sum;
attila@963 57 }
attila@963 58
attila@963 59 function g() {
attila@963 60 var diff = 17;
attila@963 61 for (var i = 0; i < a.length; i++) {
attila@963 62 diff -= a[i];
attila@963 63 }
attila@963 64 return diff;
attila@963 65 }
attila@963 66
attila@963 67 //kill anything that may already be in the event queue from earlier debug runs
attila@963 68 Debug.clearRuntimeEvents();
attila@963 69
attila@963 70 print();
attila@963 71 print(f());
attila@963 72 print(g());
attila@963 73
attila@963 74 print();
attila@963 75 events = Debug.getRuntimeEvents();
attila@963 76 print("Done with " + events.length + " in the event queue");
attila@963 77 //make sure we got runtime events
attila@963 78 print("events = " + (events.toString().indexOf("RuntimeEvent") != -1));
attila@963 79 print("events.length = " + events.length);
attila@963 80
attila@963 81 var lastInLoop = undefined;
attila@963 82 for (var i = 0; i < events.length; i++) {
attila@963 83 var e = events[i];
attila@963 84 print("event #" + i);
attila@963 85 print("\tevent class=" + e.getClass());
attila@963 86 print("\tvalueClass in event=" + getValueClass.invoke(e));
attila@963 87 var v = getValue.invoke(e);
attila@963 88 print("\tclass of value=" + v.getClass());
attila@963 89 print("\treturn type=" + getReturnType.invoke(v));
attila@963 90 lastInLoop = events[i];
attila@963 91 }
attila@963 92
attila@963 93 print();
attila@963 94 print("in loop last class = " + lastInLoop.getClass());
attila@963 95 print("in loop last value class = " + getValueClass.invoke(lastInLoop));
attila@963 96 var rexInLoop = getValue.invoke(lastInLoop);
attila@963 97 print("in loop rex class = " + rexInLoop.getClass());
attila@963 98 print("in loop rex return type = " + getReturnType.invoke(rexInLoop));
attila@963 99
attila@963 100 //try last runtime events
attila@963 101 var last = Debug.getLastRuntimeEvent();
attila@963 102 //the code after the loop creates additional rewrite exceptions
attila@963 103 print();
attila@963 104 print(last !== lastInLoop);
attila@963 105 print();
attila@963 106
attila@963 107 print("last class = " + last.getClass());
attila@963 108 print("last value class = " + getValueClass.invoke(last));
attila@963 109 var rex = getValue.invoke(last);
attila@963 110 print("rex class = " + rex.getClass());
attila@963 111 print("rex return type = " + getReturnType.invoke(rex));
attila@963 112
attila@963 113 //try the capacity setter
attila@963 114 print();
attila@963 115 print(Debug.getEventQueueCapacity());
attila@963 116 Debug.setEventQueueCapacity(2048);
attila@963 117 print(Debug.getEventQueueCapacity());
attila@963 118
attila@963 119 //try clear events
attila@963 120 print();
attila@963 121 Debug.clearRuntimeEvents();
attila@963 122 print(Debug.getRuntimeEvents().length);
attila@963 123

mercurial