Mercurial > hg > truffle
annotate graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/SpeculationLog.java @ 11833:b71a1d889db2
SpeculationLog gives back the necessary Constant when calling maySpeculate. Remove the deoptimizationReasonfrom the DebugInfo
Remove the speculationLog from LIR, it can be passed through a context to the phases that need it.
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 26 Sep 2013 16:03:28 +0200 |
parents | dce9cefed571 |
children | 5a9afbf72714 |
rev | line source |
---|---|
8217
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
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 */ |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.api.code; |
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.*; |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 /** |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 * Manages a list of unique deoptimization reasons and returns a unique index for each reason. This |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 * class is not thread safe and assumes that at every point in time there is only a single Graal |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 * compilation accessing this object. |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 * |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 */ |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 public final class SpeculationLog { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 public static final int MAX_CACHE_SIZE = 1 << 15; |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 |
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
|
39 private List<Object> speculations = new ArrayList<>(); |
8217
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 private boolean[] map = new boolean[10]; |
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
|
41 private Set<Object> snapshot = new HashSet<>(); |
8217
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
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
|
43 private short addSpeculation(Object reason) { |
8217
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 short index = (short) speculations.indexOf(reason); |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 if (index != -1) { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 // Nothing to add, reason already registered. |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 return index; |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 if (speculations.size() >= MAX_CACHE_SIZE) { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 throw new BailoutException("Too many deoptimization reasons recorded"); |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 speculations.add(reason); |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 if (map.length < speculations.size()) { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 map = Arrays.copyOf(map, map.length * 2); |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 return (short) (speculations.size() - 1); |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 public boolean[] getRawMap() { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 return map; |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 public void snapshot() { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 for (int i = 0; i < speculations.size(); ++i) { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 if (map[i]) { |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 snapshot.add(speculations.get(i)); |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
70 |
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
|
71 public Constant maySpeculate(Object reason) { |
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
|
72 if (snapshot.contains(reason)) { |
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
|
73 return null; |
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
|
74 } |
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
|
75 return Constant.forShort(addSpeculation(reason)); |
8217
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 } |
dce9cefed571
Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 } |