annotate truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/BasicLayout.java @ 22306:8bc57c7bbf88

Deprecate Layout.Builder#getAllowedImplicitCasts()
author Andreas Woess <andreas.woess@oracle.com>
date Tue, 13 Oct 2015 14:13:27 +0200
parents dc83cc1f94f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
1 /*
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
4 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
8 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
13 * accompanied this code).
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
14 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
18 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
21 * questions.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
22 */
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
23 package com.oracle.truffle.object.basic;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
24
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
25 import com.oracle.truffle.api.object.DynamicObject;
22306
8bc57c7bbf88 Deprecate Layout.Builder#getAllowedImplicitCasts()
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
26 import com.oracle.truffle.api.object.Layout;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
27 import com.oracle.truffle.api.object.Location;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
28 import com.oracle.truffle.api.object.ObjectLocation;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
29 import com.oracle.truffle.api.object.ObjectType;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
30 import com.oracle.truffle.api.object.Shape;
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
31 import com.oracle.truffle.api.object.Shape.Allocator;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
32 import com.oracle.truffle.object.LayoutImpl;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
33 import com.oracle.truffle.object.LayoutStrategy;
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
34 import com.oracle.truffle.object.LocationImpl.InternalLongLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
35 import com.oracle.truffle.object.Locations.DualLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
36 import com.oracle.truffle.object.basic.BasicLocations.ObjectFieldLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
37 import com.oracle.truffle.object.basic.BasicLocations.SimpleObjectFieldLocation;
22306
8bc57c7bbf88 Deprecate Layout.Builder#getAllowedImplicitCasts()
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
38
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
39 import java.util.EnumSet;
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41 public class BasicLayout extends LayoutImpl {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
42 private final ObjectLocation[] objectFields;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
43 private final InternalLongLocation[] primitiveFields;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44 private final Location objectArrayLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45 private final Location primitiveArrayLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
46
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
47 BasicLayout(EnumSet<ImplicitCast> allowedImplicitCasts, LayoutStrategy strategy) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
48 super(allowedImplicitCasts, DynamicObjectBasic.class, strategy);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
49 this.objectFields = DynamicObjectBasic.OBJECT_FIELD_LOCATIONS;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
50 this.primitiveFields = DynamicObjectBasic.PRIMITIVE_FIELD_LOCATIONS;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
51 this.primitiveArrayLocation = DynamicObjectBasic.PRIMITIVE_ARRAY_LOCATION;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
52 this.objectArrayLocation = DynamicObjectBasic.OBJECT_ARRAY_LOCATION;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
53 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
54
22306
8bc57c7bbf88 Deprecate Layout.Builder#getAllowedImplicitCasts()
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
55 static LayoutImpl createLayoutImpl(Layout.Builder builder, LayoutStrategy strategy) {
8bc57c7bbf88 Deprecate Layout.Builder#getAllowedImplicitCasts()
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
56 return new BasicLayout(getAllowedImplicitCasts(builder), strategy);
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
57 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
58
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
60 public DynamicObject newInstance(Shape shape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
61 return new DynamicObjectBasic(shape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
62 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
63
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
64 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
65 public Shape createShape(ObjectType operations, Object sharedData, int id) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
66 return new ShapeBasic(this, sharedData, operations, id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
67 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
68
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
69 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
70 protected boolean hasObjectExtensionArray() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
71 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
72 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
73
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
74 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
75 protected boolean hasPrimitiveExtensionArray() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
76 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
77 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
78
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
79 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
80 protected int getObjectFieldCount() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
81 return objectFields.length;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
82 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
83
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
84 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
85 protected int getPrimitiveFieldCount() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
86 return primitiveFields.length;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
87 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
88
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
89 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
90 protected Location getObjectArrayLocation() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
91 return objectArrayLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
92 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
94 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
95 protected Location getPrimitiveArrayLocation() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
96 return primitiveArrayLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
98
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
99 protected ObjectLocation getObjectFieldLocation(int index) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100 return objectFields[index];
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
101 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
103 protected InternalLongLocation getPrimitiveFieldLocation(int index) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
104 return primitiveFields[index];
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
105 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
106
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
107 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
108 public Allocator createAllocator() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
109 LayoutImpl layout = this;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110 Allocator allocator = getStrategy().createAllocator(layout);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
111 return allocator;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
112 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
113
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
114 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
115 protected int objectFieldIndex(Location location) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
116 if (location instanceof DualLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
117 return objectFieldIndex((Location) ((DualLocation) location).getObjectLocation());
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
118 } else if (location instanceof ObjectFieldLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
119 return ((ObjectFieldLocation) location).getIndex();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
120 } else if (location instanceof SimpleObjectFieldLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
121 return ((SimpleObjectFieldLocation) location).getIndex();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
122 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
123 return 0;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
124 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
125 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
126 }