annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ObjectSubstitutions.java @ 7530:5e3d1a68664e

applied mx eclipseformat to all Java files
author Doug Simon <doug.simon@oracle.com>
date Wed, 23 Jan 2013 16:34:57 +0100
parents f04a5e46cdd2
children be0d995ef51e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot.snippets;
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*;
7273
7f6bf286629c replace checked casts with unsafe casts in snippets where the exact type of a value loaded from metadata is known
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
26 import static com.oracle.graal.nodes.extended.UnsafeCastNode.*;
7368
f04a5e46cdd2 new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 7356
diff changeset
27 import static com.oracle.graal.snippets.nodes.BranchProbabilityNode.*;
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.hotspot.nodes.*;
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.snippets.*;
7229
855b2c53543f enforce that method substitution snippets are static methods
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7227
diff changeset
31 import com.oracle.graal.snippets.ClassSubstitution.MethodSubstitution;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
32 import com.oracle.graal.word.*;
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 /**
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
35 * Substitutions for {@link java.lang.Object} methods.
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 */
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 @ClassSubstitution(java.lang.Object.class)
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
38 public class ObjectSubstitutions {
7368
f04a5e46cdd2 new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 7356
diff changeset
39
7229
855b2c53543f enforce that method substitution snippets are static methods
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7227
diff changeset
40 @MethodSubstitution(isStatic = false)
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7368
diff changeset
41 public static Class<?> getClass(final Object thisObj) {
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
42 Word hub = loadHub(thisObj);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
43 return unsafeCast(hub.readFinalObject(Word.signed(classMirrorOffset())), Class.class, true, true);
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
44 }
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45
7229
855b2c53543f enforce that method substitution snippets are static methods
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7227
diff changeset
46 @MethodSubstitution(isStatic = false)
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
47 public static int hashCode(final Object thisObj) {
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
48 Word mark = loadWordFromObject(thisObj, markOffset());
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
49
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
50 // this code is independent from biased locking (although it does not look that way)
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
51 final Word biasedLock = mark.and(biasedLockMaskInPlace());
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
52 if (biasedLock == Word.unsigned(unlockedMask())) {
7368
f04a5e46cdd2 new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 7356
diff changeset
53 probability(0.99);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
54 int hash = (int) mark.unsignedShiftRight(identityHashCodeShift()).rawValue();
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
55 if (hash != uninitializedIdentityHashCodeValue()) {
7368
f04a5e46cdd2 new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 7356
diff changeset
56 probability(0.99);
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
57 return hash;
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
58 }
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
59 }
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
60
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
61 return IdentityHashCodeStubCall.call(thisObj);
7160
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 }
d526fa5640c8 replaced manual intrinsification of Object.getClass() with a snippet
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 }