annotate graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SpeculationLog.java @ 21629:36cf15e3219e

Move HotSpotResolvedJavaMethod.getSpeculationLog to ResolvedJavaMethod
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 01 Jun 2015 15:14:39 +0200
parents graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/SpeculationLog.java@f5b549811bac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 15018
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21629
36cf15e3219e Move HotSpotResolvedJavaMethod.getSpeculationLog to ResolvedJavaMethod
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21565
diff changeset
23 package com.oracle.jvmci.meta;
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.*;
13643
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
26 import java.util.concurrent.*;
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 /**
13641
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
29 * Manages a list of unique deoptimization reasons.
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
30 *
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13673
diff changeset
32 public abstract class SpeculationLog {
13643
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
33 private volatile Object lastFailed;
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
34 private volatile Collection<Object> speculations;
13641
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
35 private Set<Object> failedSpeculations;
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
13641
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
37 public synchronized void collectFailedSpeculations() {
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
38 if (lastFailed != null) {
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
39 if (failedSpeculations == null) {
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
40 failedSpeculations = new HashSet<>(2);
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 }
13641
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
42 failedSpeculations.add(lastFailed);
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
43 lastFailed = null;
13643
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
44 speculations = null;
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 }
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 }
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47
13673
bd94d77af2c1 SpeculationLog: split maySpeculate into maySpeculate (check only) and speculate (register)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13643
diff changeset
48 public boolean maySpeculate(Object reason) {
13641
5a9afbf72714 Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11833
diff changeset
49 if (failedSpeculations != null && failedSpeculations.contains(reason)) {
13673
bd94d77af2c1 SpeculationLog: split maySpeculate into maySpeculate (check only) and speculate (register)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13643
diff changeset
50 return false;
11833
b71a1d889db2 SpeculationLog gives back the necessary Constant when calling maySpeculate. Remove the deoptimizationReasonfrom the DebugInfo
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
51 }
13673
bd94d77af2c1 SpeculationLog: split maySpeculate into maySpeculate (check only) and speculate (register)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13643
diff changeset
52 return true;
bd94d77af2c1 SpeculationLog: split maySpeculate into maySpeculate (check only) and speculate (register)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13643
diff changeset
53 }
bd94d77af2c1 SpeculationLog: split maySpeculate into maySpeculate (check only) and speculate (register)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13643
diff changeset
54
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13673
diff changeset
55 protected void addSpeculation(Object reason) {
13673
bd94d77af2c1 SpeculationLog: split maySpeculate into maySpeculate (check only) and speculate (register)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13643
diff changeset
56 assert maySpeculate(reason);
13643
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
57 if (speculations == null) {
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
58 synchronized (this) {
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
59 if (speculations == null) {
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
60 speculations = new ConcurrentLinkedQueue<>();
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
61 }
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
62 }
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
63 }
4463c520f475 Keep speculations alive in the speculation log
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13641
diff changeset
64 speculations.add(reason);
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13673
diff changeset
66
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 15018
diff changeset
67 public abstract JavaConstant speculate(Object reason);
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 }