@ExplodeLoop
 public void profileArguments(Object[] args) {
   Assumption typesAssumption = profiledArgumentTypesAssumption;
   if (typesAssumption == null) {
     CompilerDirectives.transferToInterpreterAndInvalidate();
     initializeProfiledArgumentTypes(args);
   } else {
     Class<?>[] types = profiledArgumentTypes;
     if (types != null) {
       if (types.length != args.length) {
         CompilerDirectives.transferToInterpreterAndInvalidate();
         typesAssumption.invalidate();
         profiledArgumentTypes = null;
       } else if (typesAssumption.isValid()) {
         for (int i = 0; i < types.length; i++) {
           Class<?> type = types[i];
           Object value = args[i];
           if (type != null && (value == null || value.getClass() != type)) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
             updateProfiledArgumentTypes(args, types);
             break;
           }
         }
       }
     }
   }
 }
 @Override
 public double executeFloat(RubyBasicObject receiver) throws UnexpectedResultException {
   if (hasFloat && receiver.getRubyClass() == expectedClass && unmodifiedAssumption.isValid()) {
     return integerFixnumValue;
   } else {
     return next.executeFloat(receiver);
   }
 }
 @Override
 public boolean executeBoolean(RubyBasicObject receiver) throws UnexpectedResultException {
   if (hasBoolean && receiver.getRubyClass() == expectedClass && unmodifiedAssumption.isValid()) {
     return booleanValue;
   } else {
     return next.executeBoolean(receiver);
   }
 }
Beispiel #4
0
 private boolean lazyUpdate(VirtualFrame frame) {
   if (version == null || !version.isValid()) {
     CompilerDirectives.transferToInterpreterAndInvalidate();
     // i am allowed to pass in the virtual frame as its instances are always materialized
     return lazyUpdatedImpl(frame);
   }
   return true;
 }
 @Override
 public long executeLongFixnum(RubyBasicObject receiver) throws UnexpectedResultException {
   if (hasLongFixnum
       && receiver.getRubyClass() == expectedClass
       && unmodifiedAssumption.isValid()) {
     return longFixnumValue;
   } else {
     return next.executeLongFixnum(receiver);
   }
 }
  @Override
  public Object execute(RubyBasicObject receiver) {
    // TODO(CS): not sure trying next on invalid assumption is right...

    if (receiver.getRubyClass() == expectedClass && unmodifiedAssumption.isValid()) {
      return value;
    } else {
      return next.execute(receiver);
    }
  }
 @Override
 public Object call(Object... args) {
   compilationProfile.reportIndirectCall();
   if (profiledArgumentTypesAssumption != null && profiledArgumentTypesAssumption.isValid()) {
     // Argument profiling is not possible for targets of indirect calls.
     CompilerDirectives.transferToInterpreterAndInvalidate();
     profiledArgumentTypesAssumption.invalidate();
     profiledArgumentTypes = null;
   }
   return doInvoke(args);
 }
  public final Object callRoot(Object[] originalArguments) {
    Object[] args = originalArguments;
    if (CompilerDirectives.inCompiledCode()) {
      Assumption argumentTypesAssumption = this.profiledArgumentTypesAssumption;
      if (argumentTypesAssumption != null && argumentTypesAssumption.isValid()) {
        args =
            unsafeCast(
                castArrayFixedLength(args, profiledArgumentTypes.length),
                Object[].class,
                true,
                true);
        args = castArguments(args);
      }
    }

    VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args);
    Object result = callProxy(frame);

    profileReturnType(result);

    return result;
  }
 public final Object callDirect(Object... args) {
   compilationProfile.reportDirectCall();
   profileArguments(args);
   try {
     Object result = doInvoke(args);
     Class<?> klass = profiledReturnType;
     if (klass != null
         && CompilerDirectives.inCompiledCode()
         && profiledReturnTypeAssumption.isValid()) {
       result = unsafeCast(result, klass, true, true);
     }
     return result;
   } catch (Throwable t) {
     t = exceptionProfile.profile(t);
     if (t instanceof RuntimeException) {
       throw (RuntimeException) t;
     } else if (t instanceof Error) {
       throw (Error) t;
     } else {
       CompilerDirectives.transferToInterpreter();
       throw new RuntimeException(t);
     }
   }
 }