annotate truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents af393429ae26
children 47172a9b40ac
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) 2014, 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: 22143
diff changeset
25 import com.oracle.truffle.api.object.DynamicObject;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
26 import com.oracle.truffle.api.object.Layout;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
27 import com.oracle.truffle.api.object.Location;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
28 import com.oracle.truffle.api.object.Property;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
29 import com.oracle.truffle.api.object.Shape;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
30 import com.oracle.truffle.object.LayoutImpl;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
31 import com.oracle.truffle.object.LayoutStrategy;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
32 import com.oracle.truffle.object.LocationImpl;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
33 import com.oracle.truffle.object.ShapeImpl;
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
34 import com.oracle.truffle.object.ShapeImpl.BaseAllocator;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22143
diff changeset
35 import java.util.Objects;
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
36
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
37 class DefaultStrategy implements LayoutStrategy {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
38 public boolean updateShape(DynamicObject object) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
39 assert object.getShape().isValid();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40 return false;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
42
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
43 public Shape returnCached(Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44 assert newShape.isValid();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45 return newShape;
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
48 private static boolean assertLocationInRange(Shape shape, Location location) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
49 BasicLayout layout = (BasicLayout) shape.getLayout();
22143
af393429ae26 removed 7 Shape methods from the API
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
50 assert (((ShapeImpl) shape).getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount());
af393429ae26 removed 7 Shape methods from the API
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
51 assert (((ShapeImpl) shape).getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount());
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
52 return true;
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
55 public Shape ensureSpace(Shape shape, Location location) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
56 Objects.requireNonNull(location);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
57 assert assertLocationInRange(shape, location);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
58 return shape;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
60
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
61 public boolean isAutoExtArray() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
62 return false;
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
65 public Property generalizeProperty(DynamicObject object, Property oldProperty, Object value) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
66 Shape oldShape = object.getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
67 Location oldLocation = oldProperty.getLocation();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
68 Location newLocation = ((BasicAllocator) oldShape.allocator()).locationForValueUpcast(value, oldLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
69 Property newProperty = oldProperty.relocate(newLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
70 Shape newShape = oldShape.replaceProperty(oldProperty, newProperty);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
71 newProperty.setSafe(object, value, oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
72 return newProperty;
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
75 public Property generalizeProperty(DynamicObject object, Property oldProperty, Object value, Shape currentShape, Shape oldNewShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
76 Location oldLocation = oldProperty.getLocation();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
77 Location newLocation = ((BasicAllocator) currentShape.allocator()).locationForValueUpcast(value, oldLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
78 Property newProperty = oldProperty.relocate(newLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
79 Shape newShape = oldNewShape.replaceProperty(oldProperty, newProperty);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
80 newProperty.setSafe(object, value, currentShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
81 return newProperty;
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 public BaseAllocator createAllocator(Shape shape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
85 return new DefaultAllocatorImpl((ShapeImpl) shape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
86 }
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 public BaseAllocator createAllocator(Layout layout) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
89 return new DefaultAllocatorImpl((LayoutImpl) layout);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
90 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
91
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
92 public static class DefaultAllocatorImpl extends BasicAllocator {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93 protected DefaultAllocatorImpl(LayoutImpl layout) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
94 super(layout);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
95 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
96
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 protected DefaultAllocatorImpl(ShapeImpl shape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
98 super(shape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
99 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
101 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102 public Location locationForValue(Object value, boolean useFinal, boolean nonNull) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
103 return super.newDualLocationForValue(value);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
104 }
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 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
107 public Location declaredLocation(Object value) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
108 return super.newDeclaredDualLocation(value);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
109 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
111 }