annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CStringNode.java @ 19403:61d3cb8e1280

Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 17:47:43 +0100
parents 7e2c87dae93e
children 8fc336a04d77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents: 15335
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot.nodes;
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
25 import com.oracle.graal.api.meta.*;
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
26 import com.oracle.graal.graph.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16837
diff changeset
27 import com.oracle.graal.nodeinfo.*;
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.nodes.calc.*;
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
29 import com.oracle.graal.nodes.spi.*;
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.word.*;
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 /**
14731
0cb5c4d276d4 use raw data support to fix incorrect use of String.intern() for embedding strings in code
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
33 * Converts a compile-time constant Java string into a C string installed with the generated code.
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 */
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16094
diff changeset
35 @NodeInfo
18998
ec0733b5a90a Allow final modifier on node subclasses and start adding the modifier to leaf classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
36 public final class CStringNode extends FloatingNode implements LIRLowerable {
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37
19403
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19396
diff changeset
38 public static final NodeClass<CStringNode> TYPE = NodeClass.get(CStringNode.class);
17328
c9bb0da795d4 Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents: 17327
diff changeset
39 protected final String string;
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
41 public CStringNode(String string) {
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
42 super(TYPE, null);
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 this.string = string;
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 }
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45
15334
abebb5c2dc09 Use NodeLIRBuilderTool in LIRGenLowerable.
Josef Eisl <josef.eisl@jku.at>
parents: 15002
diff changeset
46 public void generate(NodeLIRBuilderTool gen) {
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
47 gen.setResult(this, emitCString(gen, string));
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
48 }
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
49
14950
d5a1206e1923 NodeLIRBuilderTool: fix typo in interface name.
Josef Eisl <josef.eisl@jku.at>
parents: 14888
diff changeset
50 public static AllocatableValue emitCString(NodeLIRBuilderTool gen, String value) {
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents: 15335
diff changeset
51 AllocatableValue dst = gen.getLIRGeneratorTool().newVariable(LIRKind.value(gen.getLIRGeneratorTool().target().wordKind));
14850
Josef Eisl <josef.eisl@jku.at>
parents: 14735
diff changeset
52 gen.getLIRGeneratorTool().emitData(dst, toCString(value));
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
53 return dst;
14731
0cb5c4d276d4 use raw data support to fix incorrect use of String.intern() for embedding strings in code
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
54 }
0cb5c4d276d4 use raw data support to fix incorrect use of String.intern() for embedding strings in code
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
55
0cb5c4d276d4 use raw data support to fix incorrect use of String.intern() for embedding strings in code
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
56 /**
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
57 * Converts a string to a null terminated byte array of ASCII characters.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14950
diff changeset
58 *
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
59 * @param s a String that must only contain ASCII characters
14731
0cb5c4d276d4 use raw data support to fix incorrect use of String.intern() for embedding strings in code
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
60 */
14735
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
61 public static byte[] toCString(String s) {
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
62 byte[] bytes = new byte[s.length() + 1];
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
63 for (int i = 0; i < s.length(); i++) {
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
64 assert s.charAt(i) < 128 : "non-ascii string: " + s;
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
65 bytes[i] = (byte) s.charAt(i);
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
66 }
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
67 bytes[s.length()] = 0;
c5ee41cf9823 replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages
Doug Simon <doug.simon@oracle.com>
parents: 14731
diff changeset
68 return bytes;
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 }
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11579
diff changeset
71 @NodeIntrinsic(setStampFromReturnType = true)
9232
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 public static native Word cstring(@ConstantNodeParameter String string);
bb2447c64055 strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 }