annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLReadPropertyCacheNode.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLReadPropertyCacheNode.java@73211b2c7c7a
children c07e64ecb528
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
1 /*
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
4 *
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
8 *
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
13 * accompanied this code).
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
14 *
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
18 *
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
21 * questions.
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
22 */
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
23 package com.oracle.truffle.sl.nodes.access;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
24
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
25 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
26 import com.oracle.truffle.api.dsl.*;
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
27 import com.oracle.truffle.api.nodes.*;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
28 import com.oracle.truffle.api.object.*;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
29 import com.oracle.truffle.sl.runtime.*;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
30
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
31 public abstract class SLReadPropertyCacheNode extends Node {
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
32
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
33 protected static final int CACHE_LIMIT = 3;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
34
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
35 protected final String propertyName;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
36
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
37 public SLReadPropertyCacheNode(String propertyName) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
38 this.propertyName = propertyName;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
39 }
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
40
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41 public static SLReadPropertyCacheNode create(String propertyName) {
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
42 return SLReadPropertyCacheNodeGen.create(propertyName);
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
43 }
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45 public abstract Object executeObject(DynamicObject receiver);
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
46
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
47 public abstract long executeLong(DynamicObject receiver) throws UnexpectedResultException;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
48
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
49 /*
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
50 * We use a separate long specialization to avoid boxing for long.
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
51 */
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
52 @Specialization(limit = "CACHE_LIMIT", guards = {"longLocation != null", "shape.check(receiver)"}, assumptions = "shape.getValidAssumption()")
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
53 @SuppressWarnings("unused")
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
54 protected long doCachedLong(DynamicObject receiver, //
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
55 @Cached("receiver.getShape()") Shape shape, //
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
56 @Cached("getLongLocation(shape)") LongLocation longLocation) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
57 return longLocation.getLong(receiver, true);
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
58 }
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
60 protected LongLocation getLongLocation(Shape shape) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
61 Property property = shape.getProperty(propertyName);
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
62 if (property != null && property.getLocation() instanceof LongLocation) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
63 return (LongLocation) property.getLocation();
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
64 }
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
65 return null;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
66 }
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
67
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
68 /*
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
69 * As soon as we have seen an object read, we cannot avoid boxing long anymore therefore we can
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
70 * contain all long cache entries.
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
71 */
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
72 @Specialization(limit = "CACHE_LIMIT", contains = "doCachedLong", guards = "shape.check(receiver)", assumptions = "shape.getValidAssumption()")
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
73 protected static Object doCachedObject(DynamicObject receiver, //
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
74 @Cached("receiver.getShape()") Shape shape, //
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
75 @Cached("shape.getProperty(propertyName)") Property property) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
76 if (property == null) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
77 return SLNull.SINGLETON;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
78 } else {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
79 return property.get(receiver, shape);
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
80 }
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
81 }
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
82
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
83 /*
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
84 * The generic case is used if the number of shapes accessed overflows the limit.
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
85 */
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
86 @Specialization(contains = "doCachedObject")
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
87 @TruffleBoundary
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
88 protected Object doGeneric(DynamicObject receiver, @Cached("new()") LRUPropertyLookup lruCache) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
89 if (!lruCache.shape.check(receiver)) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
90 Shape receiverShape = receiver.getShape();
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
91 lruCache.shape = receiverShape;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
92 lruCache.property = receiverShape.getProperty(propertyName);
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93 }
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
94 if (lruCache.property != null) {
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
95 return lruCache.property.get(receiver, true);
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
96 } else {
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 return SLNull.SINGLETON;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
98 }
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
99 }
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
101 protected static class LRUPropertyLookup {
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
103 private Shape shape;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
104 private Property property;
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
105
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
106 public LRUPropertyLookup() {
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
107 }
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
108
20954
73211b2c7c7a SL: use DSL for property reads.
Christian Humer <christian.humer@gmail.com>
parents: 18764
diff changeset
109 }
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
111 }