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