comparison truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/BasicLayout.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.object.basic/src/com/oracle/truffle/object/basic/BasicLayout.java@2c3666f44855
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2012, 2014, 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 package com.oracle.truffle.object.basic;
24
25 import java.util.*;
26
27 import com.oracle.truffle.api.object.*;
28 import com.oracle.truffle.api.object.Shape.Allocator;
29 import com.oracle.truffle.object.*;
30 import com.oracle.truffle.object.LocationImpl.InternalLongLocation;
31 import com.oracle.truffle.object.Locations.DualLocation;
32 import com.oracle.truffle.object.basic.BasicLocations.ObjectFieldLocation;
33 import com.oracle.truffle.object.basic.BasicLocations.SimpleObjectFieldLocation;
34
35 public class BasicLayout extends LayoutImpl {
36 private final ObjectLocation[] objectFields;
37 private final InternalLongLocation[] primitiveFields;
38 private final Location objectArrayLocation;
39 private final Location primitiveArrayLocation;
40
41 BasicLayout(EnumSet<ImplicitCast> allowedImplicitCasts, LayoutStrategy strategy) {
42 super(allowedImplicitCasts, DynamicObjectBasic.class, strategy);
43 this.objectFields = DynamicObjectBasic.OBJECT_FIELD_LOCATIONS;
44 this.primitiveFields = DynamicObjectBasic.PRIMITIVE_FIELD_LOCATIONS;
45 this.primitiveArrayLocation = DynamicObjectBasic.PRIMITIVE_ARRAY_LOCATION;
46 this.objectArrayLocation = DynamicObjectBasic.OBJECT_ARRAY_LOCATION;
47 }
48
49 static LayoutImpl createLayoutImpl(EnumSet<ImplicitCast> allowedImplicitCasts, LayoutStrategy strategy) {
50 return new BasicLayout(allowedImplicitCasts, strategy);
51 }
52
53 @Override
54 public DynamicObject newInstance(Shape shape) {
55 return new DynamicObjectBasic(shape);
56 }
57
58 @Override
59 public Shape createShape(ObjectType operations, Object sharedData, int id) {
60 return new ShapeBasic(this, sharedData, operations, id);
61 }
62
63 @Override
64 protected boolean hasObjectExtensionArray() {
65 return true;
66 }
67
68 @Override
69 protected boolean hasPrimitiveExtensionArray() {
70 return true;
71 }
72
73 @Override
74 protected int getObjectFieldCount() {
75 return objectFields.length;
76 }
77
78 @Override
79 protected int getPrimitiveFieldCount() {
80 return primitiveFields.length;
81 }
82
83 @Override
84 protected Location getObjectArrayLocation() {
85 return objectArrayLocation;
86 }
87
88 @Override
89 protected Location getPrimitiveArrayLocation() {
90 return primitiveArrayLocation;
91 }
92
93 protected ObjectLocation getObjectFieldLocation(int index) {
94 return objectFields[index];
95 }
96
97 protected InternalLongLocation getPrimitiveFieldLocation(int index) {
98 return primitiveFields[index];
99 }
100
101 @Override
102 public Allocator createAllocator() {
103 LayoutImpl layout = this;
104 Allocator allocator = getStrategy().createAllocator(layout);
105 return allocator;
106 }
107
108 @Override
109 protected int objectFieldIndex(Location location) {
110 if (location instanceof DualLocation) {
111 return objectFieldIndex((Location) ((DualLocation) location).getObjectLocation());
112 } else if (location instanceof ObjectFieldLocation) {
113 return ((ObjectFieldLocation) location).getIndex();
114 } else if (location instanceof SimpleObjectFieldLocation) {
115 return ((SimpleObjectFieldLocation) location).getIndex();
116 } else {
117 return 0;
118 }
119 }
120 }