Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java @ 22288:47172a9b40ac
Object model refactoring, add Shape#defineProperty
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Wed, 07 Oct 2015 19:15:14 +0200 |
parents | dc83cc1f94f2 |
children | cf203af4610c |
comparison
equal
deleted
inserted
replaced
22287:479028cce974 | 22288:47172a9b40ac |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.object.basic; | 23 package com.oracle.truffle.object.basic; |
24 | 24 |
25 import java.util.Objects; | |
26 | |
25 import com.oracle.truffle.api.object.DynamicObject; | 27 import com.oracle.truffle.api.object.DynamicObject; |
26 import com.oracle.truffle.api.object.Layout; | 28 import com.oracle.truffle.api.object.Layout; |
27 import com.oracle.truffle.api.object.Location; | 29 import com.oracle.truffle.api.object.Location; |
28 import com.oracle.truffle.api.object.Property; | 30 import com.oracle.truffle.api.object.Property; |
29 import com.oracle.truffle.api.object.Shape; | 31 import com.oracle.truffle.api.object.Shape; |
30 import com.oracle.truffle.object.LayoutImpl; | 32 import com.oracle.truffle.object.LayoutImpl; |
31 import com.oracle.truffle.object.LayoutStrategy; | 33 import com.oracle.truffle.object.LayoutStrategy; |
32 import com.oracle.truffle.object.LocationImpl; | 34 import com.oracle.truffle.object.LocationImpl; |
33 import com.oracle.truffle.object.ShapeImpl; | 35 import com.oracle.truffle.object.ShapeImpl; |
34 import com.oracle.truffle.object.ShapeImpl.BaseAllocator; | 36 import com.oracle.truffle.object.ShapeImpl.BaseAllocator; |
35 import java.util.Objects; | |
36 | 37 |
37 class DefaultStrategy implements LayoutStrategy { | 38 class DefaultStrategy extends LayoutStrategy { |
39 @Override | |
38 public boolean updateShape(DynamicObject object) { | 40 public boolean updateShape(DynamicObject object) { |
39 assert object.getShape().isValid(); | 41 assert object.getShape().isValid(); |
40 return false; | 42 return false; |
41 } | 43 } |
42 | 44 |
43 public Shape returnCached(Shape newShape) { | 45 @Override |
46 public Shape ensureValid(Shape newShape) { | |
44 assert newShape.isValid(); | 47 assert newShape.isValid(); |
45 return newShape; | 48 return newShape; |
46 } | 49 } |
47 | 50 |
48 private static boolean assertLocationInRange(Shape shape, Location location) { | 51 private static boolean assertLocationInRange(Shape shape, Location location) { |
50 assert (((ShapeImpl) shape).getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount()); | 53 assert (((ShapeImpl) shape).getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount()); |
51 assert (((ShapeImpl) shape).getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount()); | 54 assert (((ShapeImpl) shape).getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount()); |
52 return true; | 55 return true; |
53 } | 56 } |
54 | 57 |
58 @Override | |
55 public Shape ensureSpace(Shape shape, Location location) { | 59 public Shape ensureSpace(Shape shape, Location location) { |
56 Objects.requireNonNull(location); | 60 Objects.requireNonNull(location); |
57 assert assertLocationInRange(shape, location); | 61 assert assertLocationInRange(shape, location); |
58 return shape; | 62 return shape; |
59 } | 63 } |
60 | 64 |
65 @Override | |
61 public boolean isAutoExtArray() { | 66 public boolean isAutoExtArray() { |
62 return false; | 67 return false; |
63 } | 68 } |
64 | 69 |
65 public Property generalizeProperty(DynamicObject object, Property oldProperty, Object value) { | 70 @Override |
66 Shape oldShape = object.getShape(); | 71 public ShapeAndProperty generalizeProperty(Property oldProperty, Object value, Shape currentShape, Shape nextShape) { |
67 Location oldLocation = oldProperty.getLocation(); | |
68 Location newLocation = ((BasicAllocator) oldShape.allocator()).locationForValueUpcast(value, oldLocation); | |
69 Property newProperty = oldProperty.relocate(newLocation); | |
70 Shape newShape = oldShape.replaceProperty(oldProperty, newProperty); | |
71 newProperty.setSafe(object, value, oldShape, newShape); | |
72 return newProperty; | |
73 } | |
74 | |
75 public Property generalizeProperty(DynamicObject object, Property oldProperty, Object value, Shape currentShape, Shape oldNewShape) { | |
76 Location oldLocation = oldProperty.getLocation(); | 72 Location oldLocation = oldProperty.getLocation(); |
77 Location newLocation = ((BasicAllocator) currentShape.allocator()).locationForValueUpcast(value, oldLocation); | 73 Location newLocation = ((BasicAllocator) currentShape.allocator()).locationForValueUpcast(value, oldLocation); |
78 Property newProperty = oldProperty.relocate(newLocation); | 74 Property newProperty = oldProperty.relocate(newLocation); |
79 Shape newShape = oldNewShape.replaceProperty(oldProperty, newProperty); | 75 Shape newShape = nextShape.replaceProperty(oldProperty, newProperty); |
80 newProperty.setSafe(object, value, currentShape, newShape); | 76 return new ShapeAndProperty(newShape, newProperty); |
81 return newProperty; | |
82 } | 77 } |
83 | 78 |
79 @Override | |
84 public BaseAllocator createAllocator(Shape shape) { | 80 public BaseAllocator createAllocator(Shape shape) { |
85 return new DefaultAllocatorImpl((ShapeImpl) shape); | 81 return new DefaultAllocatorImpl((ShapeImpl) shape); |
86 } | 82 } |
87 | 83 |
84 @Override | |
88 public BaseAllocator createAllocator(Layout layout) { | 85 public BaseAllocator createAllocator(Layout layout) { |
89 return new DefaultAllocatorImpl((LayoutImpl) layout); | 86 return new DefaultAllocatorImpl((LayoutImpl) layout); |
90 } | 87 } |
91 | 88 |
92 public static class DefaultAllocatorImpl extends BasicAllocator { | 89 public static class DefaultAllocatorImpl extends BasicAllocator { |