1 /*
2  * Copyright (c) 2015, 2018, 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 package org.graalvm.compiler.nodes;
26 
27 import java.util.List;
28 
29 import jdk.internal.vm.compiler.collections.EconomicSet;
30 import org.graalvm.compiler.graph.NodeClass;
31 
32 import jdk.vm.ci.meta.Assumptions;
33 import jdk.vm.ci.meta.ResolvedJavaField;
34 import jdk.vm.ci.meta.ResolvedJavaMethod;
35 
36 /**
37  * A {@link StructuredGraph} encoded in a compact binary representation as a byte[] array. See
38  * {@link GraphEncoder} for a description of the encoding format. Use {@link GraphDecoder} for
39  * decoding.
40  */
41 public class EncodedGraph {
42 
43     private final byte[] encoding;
44     private final int startOffset;
45     protected final Object[] objects;
46     private final NodeClass<?>[] types;
47     private final Assumptions assumptions;
48     private final List<ResolvedJavaMethod> inlinedMethods;
49     private final boolean trackNodeSourcePosition;
50     private final EconomicSet<ResolvedJavaField> fields;
51     private final boolean hasUnsafeAccess;
52 
53     /**
54      * The "table of contents" of the encoded graph, i.e., the mapping from orderId numbers to the
55      * offset in the encoded byte[] array. Used as a cache during decoding.
56      */
57     protected int[] nodeStartOffsets;
58 
EncodedGraph(byte[] encoding, int startOffset, Object[] objects, NodeClass<?>[] types, StructuredGraph sourceGraph)59     public EncodedGraph(byte[] encoding, int startOffset, Object[] objects, NodeClass<?>[] types, StructuredGraph sourceGraph) {
60         this(encoding, startOffset, objects, types, sourceGraph.getAssumptions(), sourceGraph.getMethods(), sourceGraph.getFields(), sourceGraph.hasUnsafeAccess(),
61                         sourceGraph.trackNodeSourcePosition());
62     }
63 
EncodedGraph(byte[] encoding, int startOffset, Object[] objects, NodeClass<?>[] types, Assumptions assumptions, List<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> fields, boolean hasUnsafeAccess, boolean trackNodeSourcePosition)64     public EncodedGraph(byte[] encoding, int startOffset, Object[] objects, NodeClass<?>[] types, Assumptions assumptions, List<ResolvedJavaMethod> inlinedMethods,
65                     EconomicSet<ResolvedJavaField> fields, boolean hasUnsafeAccess, boolean trackNodeSourcePosition) {
66         this.encoding = encoding;
67         this.startOffset = startOffset;
68         this.objects = objects;
69         this.types = types;
70         this.assumptions = assumptions;
71         this.inlinedMethods = inlinedMethods;
72         this.trackNodeSourcePosition = trackNodeSourcePosition;
73         this.fields = fields;
74         this.hasUnsafeAccess = hasUnsafeAccess;
75     }
76 
getEncoding()77     public byte[] getEncoding() {
78         return encoding;
79     }
80 
getStartOffset()81     public int getStartOffset() {
82         return startOffset;
83     }
84 
getObjects()85     public Object[] getObjects() {
86         return objects;
87     }
88 
getNumObjects()89     public int getNumObjects() {
90         return objects.length;
91     }
92 
getObject(int i)93     public Object getObject(int i) {
94         return objects[i];
95     }
96 
getNodeClasses()97     public NodeClass<?>[] getNodeClasses() {
98         return types;
99     }
100 
getAssumptions()101     public Assumptions getAssumptions() {
102         return assumptions;
103     }
104 
getInlinedMethods()105     public List<ResolvedJavaMethod> getInlinedMethods() {
106         return inlinedMethods;
107     }
108 
trackNodeSourcePosition()109     public boolean trackNodeSourcePosition() {
110         return trackNodeSourcePosition;
111     }
112 
getFields()113     public EconomicSet<ResolvedJavaField> getFields() {
114         return fields;
115     }
116 
hasUnsafeAccess()117     public boolean hasUnsafeAccess() {
118         return hasUnsafeAccess;
119     }
120 
121     @SuppressWarnings("unused")
isCallToOriginal(ResolvedJavaMethod callTarget)122     public boolean isCallToOriginal(ResolvedJavaMethod callTarget) {
123         return false;
124     }
125 }
126