private boolean processPhi(ValuePhiNode phi,PartialEscapeBlockState<?>[] states,int[] mergedVirtualObjects){
  int virtualInputs=0;
  boolean uniqueVirtualObject=true;
  boolean ensureVirtual=true;
  VirtualObjectNode[] virtualObjs=new VirtualObjectNode[states.length];
  for (int i=0; i < states.length; i++) {
    ValueNode alias=getAlias(getPhiValueAt(phi,i));
    if (alias instanceof VirtualObjectNode) {
      VirtualObjectNode virtual=(VirtualObjectNode)alias;
      virtualObjs[i]=virtual;
      ObjectState objectState=states[i].getObjectStateOptional(virtual);
      if (objectState == null) {
        assert getPhiValueAt(phi,i) instanceof PhiNode : "this should only happen for phi nodes";
        return false;
      }
      if (objectState.isVirtual()) {
        if (virtualObjs[0] != alias) {
          uniqueVirtualObject=false;
        }
        ensureVirtual&=objectState.getEnsureVirtualized();
        virtualInputs++;
      }
    }
  }
  if (virtualInputs == states.length) {
    if (uniqueVirtualObject) {
      addAndMarkAlias(virtualObjs[0],phi);
      mergeEffects.deleteNode(phi);
      return false;
    }
 else {
      boolean compatible=true;
      boolean hasIdentity=false;
      VirtualObjectNode firstVirtual=virtualObjs[0];
      for (int i=0; i < states.length; i++) {
        VirtualObjectNode virtual=virtualObjs[i];
        hasIdentity|=virtual.hasIdentity();
        boolean identitySurvives=virtual.hasIdentity() && Arrays.asList(mergedVirtualObjects).contains(virtual.getObjectId());
        if (identitySurvives || !firstVirtual.type().equals(virtual.type()) || firstVirtual.entryCount() != virtual.entryCount()) {
          compatible=false;
          break;
        }
        if (!states[0].getObjectState(firstVirtual).locksEqual(states[i].getObjectState(virtual))) {
          compatible=false;
          break;
        }
      }
      if (compatible && !hasIdentity) {
        VirtualObjectNode virtual=getValueObjectVirtual(phi,virtualObjs[0]);
        mergeEffects.addFloatingNode(virtual,"valueObjectNode");
        mergeEffects.deleteNode(phi);
        if (virtual.getObjectId() == -1) {
          int id=virtualObjects.size();
          virtualObjects.add(virtual);
          virtual.setObjectId(id);
        }
        int[] virtualObjectIds=new int[states.length];
        for (int i=0; i < states.length; i++) {
          virtualObjectIds[i]=virtualObjs[i].getObjectId();
        }
        boolean materialized=mergeObjectStates(virtual.getObjectId(),virtualObjectIds,states);
        addAndMarkAlias(virtual,virtual);
        addAndMarkAlias(virtual,phi);
        return materialized;
      }
    }
  }
  boolean materialized=false;
  if (virtualInputs > 0) {
    for (int i=0; i < states.length; i++) {
      VirtualObjectNode virtual=virtualObjs[i];
      if (virtual != null) {
        Block predecessor=getPredecessor(i);
        if (!ensureVirtual && states[i].getObjectState(virtual).isVirtual()) {
          states[i].getObjectState(virtual).setEnsureVirtualized(false);
        }
        materialized|=ensureMaterialized(states[i],virtual.getObjectId(),predecessor.getEndNode(),blockEffects.get(predecessor),COUNTER_MATERIALIZATIONS_PHI);
      }
    }
  }
  for (int i=0; i < states.length; i++) {
    VirtualObjectNode virtual=virtualObjs[i];
    if (virtual != null) {
      setPhiInput(phi,i,getAliasAndResolve(states[i],virtual));
    }
  }
  return materialized;
}

private boolean processPhi ( ValuePhiNode phi , PartialEscapeBlockState < ? > [ ] states , int [ ] mergedVirtualObjects ) { int virtualInputs = 0 ; boolean uniqueVirtualObject = true ; boolean ensureVirtual = true ; VirtualObjectNode [ ] virtualObjs = new VirtualObjectNode [ states . length ] ; for ( int i = 0 ; i < states . length ; i ++ ) { ValueNode alias = getAlias ( getPhiValueAt ( phi , i ) ) ; if ( alias instanceof VirtualObjectNode ) { VirtualObjectNode virtual = ( VirtualObjectNode ) alias ; virtualObjs [ i ] = virtual ; ObjectState objectState = states [ i ] . getObjectStateOptional ( virtual ) ; if ( objectState == null ) { assert getPhiValueAt ( phi , i ) instanceof PhiNode : "this should only happen for phi nodes" ; return false ; } if ( objectState . isVirtual ( ) ) { if ( virtualObjs [ 0 ] != alias ) { uniqueVirtualObject = false ; } ensureVirtual &= objectState . getEnsureVirtualized ( ) ; virtualInputs ++ ; } } } if ( virtualInputs == states . length ) { if ( uniqueVirtualObject ) { addAndMarkAlias ( virtualObjs [ 0 ] , phi ) ; mergeEffects . deleteNode ( phi ) ; return false ; } else { boolean compatible = true ; boolean hasIdentity = false ; VirtualObjectNode firstVirtual = virtualObjs [ 0 ] ; for ( int i = 0 ; i < states . length ; i ++ ) { VirtualObjectNode virtual = virtualObjs [ i ] ; hasIdentity |= virtual . hasIdentity ( ) ; boolean identitySurvives = virtual . hasIdentity ( ) && Arrays . asList ( mergedVirtualObjects ) . contains ( virtual . getObjectId ( ) ) ; if ( identitySurvives || ! firstVirtual . type ( ) . equals ( virtual . type ( ) ) || firstVirtual . entryCount ( ) != virtual . entryCount ( ) ) { compatible = false ; break ; } if ( ! states [ 0 ] . getObjectState ( firstVirtual ) . locksEqual ( states [ i ] . getObjectState ( virtual ) ) ) { compatible = false ; break ; } } if ( compatible && ! hasIdentity ) { VirtualObjectNode virtual = getValueObjectVirtual ( phi , virtualObjs [ 0 ] ) ; mergeEffects . addFloatingNode ( virtual , "valueObjectNode" ) ; mergeEffects . deleteNode ( phi ) ; if ( virtual . getObjectId ( ) == - 1 ) { int id = virtualObjects . size ( ) ; virtualObjects . add ( virtual ) ; virtual . setObjectId ( id ) ; } int [ ] virtualObjectIds = new int [ states . length ] ; for ( int i = 0 ; i < states . length ; i ++ ) { virtualObjectIds [ i ] = virtualObjs [ i ] . getObjectId ( ) ; } boolean materialized = mergeObjectStates ( virtual . getObjectId ( ) , virtualObjectIds , states ) ; addAndMarkAlias ( virtual , virtual ) ; addAndMarkAlias ( virtual , phi ) ; return materialized ; } } } boolean materialized = false ; if ( virtualInputs > 0 ) { for ( int i = 0 ; i < states . length ; i ++ ) { VirtualObjectNode virtual = virtualObjs [ i ] ; if ( virtual != null ) { Block predecessor = getPredecessor ( i ) ; if ( ! ensureVirtual && states [ i ] . getObjectState ( virtual ) . isVirtual ( ) ) { states [ i ] . getObjectState ( virtual ) . setEnsureVirtualized ( false ) ; } materialized |= ensureMaterialized ( states [ i ] , virtual . getObjectId ( ) , predecessor . getEndNode ( ) , blockEffects . get ( predecessor ) , COUNTER_MATERIALIZATIONS_PHI ) ; } } } for ( int i = 0 ; i < states . length ; i ++ ) { VirtualObjectNode virtual = virtualObjs [ i ] ; if ( virtual != null ) { setPhiInput ( phi , i , getAliasAndResolve ( states [ i ] , virtual ) ) ; } } return materialized ; }
examine a phinode and try to replace it with merging of virtual objects if all its inputs refer to virtual object states . in order for the merging to happen , all incoming object states need to be compatible and without object identity ( meaning that their object identity if not used later on ) .
