Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java @ 18627:196cf131ed32
OM: extract queryTransition method
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Thu, 04 Dec 2014 19:36:50 +0100 |
parents | ce46f909c176 |
children | 6db7923af642 |
comparison
equal
deleted
inserted
replaced
18626:ce46f909c176 | 18627:196cf131ed32 |
---|---|
316 | 316 |
317 public final PropertyMap getPropertyMap() { | 317 public final PropertyMap getPropertyMap() { |
318 return propertyMap; | 318 return propertyMap; |
319 } | 319 } |
320 | 320 |
321 private ShapeImpl queryTransition(Transition transition) { | |
322 ShapeImpl cachedShape = this.getTransitionMapForRead().get(transition); | |
323 if (cachedShape != null) { // Shape already exists? | |
324 shapeCacheHitCount.inc(); | |
325 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); | |
326 } | |
327 shapeCacheMissCount.inc(); | |
328 | |
329 return null; | |
330 } | |
331 | |
321 /** | 332 /** |
322 * Add a new property in the map, yielding a new or cached Shape object. | 333 * Add a new property in the map, yielding a new or cached Shape object. |
323 * | 334 * |
324 * @param property the property to add | 335 * @param property the property to add |
325 * @return the new Shape | 336 * @return the new Shape |
345 CompilerAsserts.neverPartOfCompilation(); | 356 CompilerAsserts.neverPartOfCompilation(); |
346 assert prop.isShadow() || !(this.hasProperty(prop.getKey())) : "duplicate property"; | 357 assert prop.isShadow() || !(this.hasProperty(prop.getKey())) : "duplicate property"; |
347 assert !getPropertyListInternal(false).contains(prop); | 358 assert !getPropertyListInternal(false).contains(prop); |
348 // invalidatePropertyAssumption(prop.getName()); | 359 // invalidatePropertyAssumption(prop.getName()); |
349 | 360 |
350 AddPropertyTransition key = new AddPropertyTransition(prop); | 361 AddPropertyTransition addTransition = new AddPropertyTransition(prop); |
351 Map<Transition, ShapeImpl> transitionMapForRead = this.getTransitionMapForRead(); | 362 ShapeImpl cachedShape = queryTransition(addTransition); |
352 ShapeImpl cachedShape = transitionMapForRead.get(key); | 363 if (cachedShape != null) { |
353 if (cachedShape != null) { // Shape already exists? | 364 return cachedShape; |
354 shapeCacheHitCount.inc(); | 365 } |
355 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); | |
356 } | |
357 shapeCacheMissCount.inc(); | |
358 | 366 |
359 ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, prop.getLocation()); | 367 ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, prop.getLocation()); |
360 | 368 |
361 ShapeImpl newShape = makeShapeWithAddedProperty(oldShape, key); | 369 ShapeImpl newShape = makeShapeWithAddedProperty(oldShape, addTransition); |
362 oldShape.addDirectTransition(key, newShape); | 370 oldShape.addDirectTransition(addTransition, newShape); |
363 return newShape; | 371 return newShape; |
364 } | 372 } |
365 | 373 |
366 protected ShapeImpl cloneRoot(ShapeImpl from, Object newSharedData) { | 374 protected ShapeImpl cloneRoot(ShapeImpl from, Object newSharedData) { |
367 return createShape(from.layout, newSharedData, null, from.objectType, from.propertyMap, null, from.allocator(), from.id); | 375 return createShape(from.layout, newSharedData, null, from.objectType, from.propertyMap, null, from.allocator(), from.id); |
415 return newShape; | 423 return newShape; |
416 } | 424 } |
417 | 425 |
418 private ShapeImpl addPrimitiveExtensionArray() { | 426 private ShapeImpl addPrimitiveExtensionArray() { |
419 assert layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray(); | 427 assert layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray(); |
420 Transition key = new ReservePrimitiveArrayTransition(); | 428 Transition transition = new ReservePrimitiveArrayTransition(); |
421 ShapeImpl cachedShape = this.getTransitionMapForRead().get(key); | 429 ShapeImpl cachedShape = queryTransition(transition); |
422 if (cachedShape != null) { | 430 if (cachedShape != null) { |
423 shapeCacheHitCount.inc(); | 431 return cachedShape; |
424 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); | 432 } |
425 } | |
426 shapeCacheMissCount.inc(); | |
427 | 433 |
428 ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, layout.getPrimitiveArrayLocation()); | 434 ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, layout.getPrimitiveArrayLocation()); |
429 ShapeImpl newShape = makeShapeWithPrimitiveExtensionArray(oldShape, key); | 435 ShapeImpl newShape = makeShapeWithPrimitiveExtensionArray(oldShape, transition); |
430 oldShape.addDirectTransition(key, newShape); | 436 oldShape.addDirectTransition(transition, newShape); |
431 return newShape; | 437 return newShape; |
432 } | 438 } |
433 | 439 |
434 /** | 440 /** |
435 * Are these two shapes related, i.e. do they have the same root? | 441 * Are these two shapes related, i.e. do they have the same root? |
627 | 633 |
628 @TruffleBoundary | 634 @TruffleBoundary |
629 @Override | 635 @Override |
630 public final ShapeImpl removeProperty(Property prop) { | 636 public final ShapeImpl removeProperty(Property prop) { |
631 RemovePropertyTransition transition = new RemovePropertyTransition(prop); | 637 RemovePropertyTransition transition = new RemovePropertyTransition(prop); |
632 ShapeImpl cachedShape = getTransitionMapForRead().get(transition); | 638 ShapeImpl cachedShape = queryTransition(transition); |
633 if (cachedShape != null) { | 639 if (cachedShape != null) { |
634 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); | 640 return cachedShape; |
635 } | 641 } |
636 | 642 |
637 ShapeImpl shape = getShapeFromProperty(prop); | 643 ShapeImpl shape = getShapeFromProperty(prop); |
638 if (shape != null) { | 644 if (shape != null) { |
639 List<Transition> transitionList = new ArrayList<>(); | 645 List<Transition> transitionList = new ArrayList<>(); |
682 * Duplicate shape exchanging existing property with new property. | 688 * Duplicate shape exchanging existing property with new property. |
683 */ | 689 */ |
684 @Override | 690 @Override |
685 public final ShapeImpl replaceProperty(Property oldProperty, Property newProperty) { | 691 public final ShapeImpl replaceProperty(Property oldProperty, Property newProperty) { |
686 Transition replacePropertyTransition = new Transition.ReplacePropertyTransition(oldProperty, newProperty); | 692 Transition replacePropertyTransition = new Transition.ReplacePropertyTransition(oldProperty, newProperty); |
687 ShapeImpl cachedShape = getTransitionMapForRead().get(replacePropertyTransition); | 693 ShapeImpl cachedShape = queryTransition(replacePropertyTransition); |
688 if (cachedShape != null) { | 694 if (cachedShape != null) { |
689 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); | 695 return cachedShape; |
690 } | 696 } |
691 | 697 |
692 ShapeImpl top = this; | 698 ShapeImpl top = this; |
693 List<Transition> transitionList = new ArrayList<>(); | 699 List<Transition> transitionList = new ArrayList<>(); |
694 boolean found = false; | 700 boolean found = false; |
759 newShape = newShape.addPropertyInternal(p); | 765 newShape = newShape.addPropertyInternal(p); |
760 } | 766 } |
761 return newShape; | 767 return newShape; |
762 } | 768 } |
763 | 769 |
764 /** | |
765 * NB: this is not an accurate property count. | |
766 */ | |
767 @Override | 770 @Override |
768 public final int getPropertyCount() { | 771 public final int getPropertyCount() { |
769 return propertyCount; | 772 return propertyCount; |
770 } | 773 } |
771 | 774 |
844 | 847 |
845 @Override | 848 @Override |
846 @TruffleBoundary | 849 @TruffleBoundary |
847 public final ShapeImpl changeType(ObjectType newOps) { | 850 public final ShapeImpl changeType(ObjectType newOps) { |
848 ObjectTypeTransition transition = new ObjectTypeTransition(newOps); | 851 ObjectTypeTransition transition = new ObjectTypeTransition(newOps); |
849 ShapeImpl cachedShape = getTransitionMapForRead().get(transition); | 852 ShapeImpl cachedShape = queryTransition(transition); |
850 if (cachedShape != null) { | 853 if (cachedShape != null) { |
851 return cachedShape; | 854 return cachedShape; |
852 } else { | 855 } |
853 ShapeImpl newShape = createShape(layout, sharedData, this, newOps, propertyMap, transition, allocator(), id); | 856 |
854 addDirectTransition(transition, newShape); | 857 ShapeImpl newShape = createShape(layout, sharedData, this, newOps, propertyMap, transition, allocator(), id); |
855 return newShape; | 858 addDirectTransition(transition, newShape); |
856 } | 859 return newShape; |
857 } | 860 } |
858 | 861 |
859 @Override | 862 @Override |
860 public final ShapeImpl reservePrimitiveExtensionArray() { | 863 public final ShapeImpl reservePrimitiveExtensionArray() { |
861 if (layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray()) { | 864 if (layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray()) { |