Package ch.ethz.jvmai

Examples of ch.ethz.jvmai.JVMAIRuntimeException


  public int getMask() {
    return MASK_CODE_JP | MASK_FIELD_JP | MASK_FIELD_ACCESS_JP;
  }

  public void setValue(Object obj) {
    throw new JVMAIRuntimeException("Not implemented for Stub and Advice Weavers implementation.");
  }
View Full Code Here


   *
   * @param pkg
   */
  public void registrationRequest( Package pkg ) {
    if( null == aspectInterface )
      throw new JVMAIRuntimeException( this.getClass().getName() + ".setAspectInterface() must be called first");

    Integer regCount = (Integer) registeredPackages.get( pkg )
    if( null == regCount ) {
      if( ! registerAll ) {
        String packageName = pkg.getName();
View Full Code Here

   *
   * @param cls
   */
  public void registrationRequestSubClasses( Class cls ) {
    if( null == aspectInterface )
      throw new JVMAIRuntimeException( this.getClass().getName() + ".setAspectInterface() must be called first");

    Integer regCount = (Integer) registeredSuperClasses.get( cls );
    if( null == regCount ) {
      if( ! registerAll ) {
        List loadedClasses = aspectInterface.getLoadedClasses();
View Full Code Here

   * New loaded classes will also be scanned until {@link #removeRequestAll
   * removeRequestAll()} is called.
   */
  public void registrationRequestAll() {
    if( null == aspectInterface )
      throw new JVMAIRuntimeException( this.getClass().getName() + ".setAspectInterface() must be called first");

    registerAllCount++;

    if( ! registerAll ) {
      registerAll = true;
View Full Code Here

      HotSwapFieldWeaver fw = (HotSwapFieldWeaver) HotSwapFieldWeaver.weaverNames.get( fkey );
      if( null != fw && (HotSwapFieldWeaver.FW_ACCESS_ENABLED & fw.status) > 0 ) {
        // Weave method
        MethodWeaver mw;
        try{ mw = HotSwapClassWeaver.getWeaver( HotSwapAspectInterfaceImpl.getMethodFromString( key ) ); }
        catch(ClassNotFoundException e) { throw new JVMAIRuntimeException( "scanning a class file, but can not find the class: " + e.getMessage() ); }
        mw.addFieldAccessor( fw );
        weave = true;
      }
    }
View Full Code Here

      HotSwapFieldWeaver fw = (HotSwapFieldWeaver) HotSwapFieldWeaver.weaverNames.get( fkey );
      if( null != fw && (HotSwapFieldWeaver.FW_MODIFICATION_ENABLED & fw.status) > 0 ) {
        // Weave method
        MethodWeaver mw;
        try{ mw = HotSwapClassWeaver.getWeaver( HotSwapAspectInterfaceImpl.getMethodFromString( key ) ); }
        catch(ClassNotFoundException e) { throw new JVMAIRuntimeException( "scanning a class file, but can not find the class: " + e.getMessage() ); }
        mw.addFieldModifier( fw );
        weave = true;
      }
    }
View Full Code Here

      }
    }

    private Field resolveFieldName( FieldInstruction obj, boolean isStatic ) {
      try{ return HotSwapAspectInterfaceImpl.getFieldFromString( obj.getReferenceType(cpGen).toString(), obj.getName(cpGen), obj.getSignature(cpGen), isStatic ); }
      catch(Exception e) { throw new JVMAIRuntimeException("can not resolve field " + obj.getReferenceType(cpGen).toString() + "." + obj.getName(cpGen) + ": " + e.getClass().getName() + ": " + e.getMessage() ); }
    }
View Full Code Here

    if( ! f.isAccessible() );
    f.setAccessible( true );
    try { f.set( owner, value ); }
    // If this handler is reached, something went wrong at
    // the f.isAccessible() or f.setAccessible() call above.
    catch( IllegalAccessException e ) { throw new JVMAIRuntimeException("Illigal field access: this should never happen"); }
  }
View Full Code Here

          for(int i = maxDefined; i < newDefinedParameters.length; i++)
            newDefinedParameters[i] = baseType;//Type.OBJECT;
          // 2.a.2.3. replace 'definedParameters'
          definedParameters = newDefinedParameters;
        }
      } catch(ClassNotFoundException e) {throw new JVMAIRuntimeException(e.getMessage());}
    }

    // 3. remove signature pattern arguments (if any).
    //    All instructions accessing arguments of type 'ANY' or 'REST'
    //    must be removed before redefining 'target' method.
View Full Code Here

        if(((ReferenceType)inType).isAssignmentCompatibleWith(outType))
          // No boxing required if inType may be assigned to outType
          return;
//gery-angy    else
//gery-angy      throw new IllegalProceedUsageException("incompatible argument or return type for 'proceed()'");
      } catch(ClassNotFoundException e) {throw new JVMAIRuntimeException(e.getMessage());}
     
    if(!(inType instanceof ObjectType) && !(outType instanceof ObjectType))
      throw new IllegalProceedUsageException("cannot convert from " + inType + " to " + outType + " for 'proceed()' statement (wrong type for an argument or return value)");
   
    if(inType instanceof ObjectType) {
      // outboxing (object -> primitive type)
      //
      // NOTE: insert inserts always at the begining of the instruction list
      //       so the instructions are inserted in reverse order
      //       (the last inserted instruction will be the first in the list).
      //
      //       Casting may cause runtime exceptions, it may be safer to not
      //       insert the 'CHECKCAST' instruction.
      //
      try {
        ObjectType rType = (ObjectType)inType;
        boolean noCast;
       
        if(Type.BOOLEAN.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(booleanType))
              || booleanType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Boolean", "booleanValue", "()Z")));
            if(!noCast
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Boolean")));
            return;
          }
        }
        else if(Type.BYTE.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(byteType))
              || byteType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Byte", "byteValue", "()B")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Byte")));
            return;
          }
        }
        else if(Type.CHAR.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(characterType))
              || characterType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Character", "charValue", "()C")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Character")));
            return;
          }
        }
        else if(Type.DOUBLE.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(doubleType))
              || doubleType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Double", "doubleValue", "()D")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Double")));
            return;
          }
        }
        else if(Type.FLOAT.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(floatType))
              || floatType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Float", "floatValue", "()F")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Float")));
            return;
          }
        }
        else if(Type.INT.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(integerType))
              || integerType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Integer", "intValue", "()I")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Integer")));
            return;
          }
        }
        else if(Type.LONG.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(longType))
              || longType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Long", "longValue", "()J")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Long")));
            return;
          }
        }
        else if(Type.SHORT.equals(outType)) {
          if(
              (noCast = rType.isAssignmentCompatibleWith(shortType))
              || shortType.isAssignmentCompatibleWith(rType)
          ) {
            instructions.insert(new INVOKEVIRTUAL(cpGen.addMethodref("java.lang.Short", "shortValue", "()S")));
            if(!noCast)
              instructions.insert(new CHECKCAST(cpGen.addClass("java.lang.Short")));
            return;
          }
        }
        else { //gery-angy
          instructions.insert(new CHECKCAST(cpGen.addClass(outType.toString()))); //gery-angy
          return//gery-angy
        //gery-angy
//        throw new IllegalProceedUsageException("cannot outbox from " + inType + " to " + outType);  //BEFORE
      } catch(ClassNotFoundException e) {throw new JVMAIRuntimeException(e.getMessage());}
    }
    else {
      // inboxing (primitive type -> object)
      //
      // Stack instructions have to move the arguments for the constructor
      // into the right position on the stack.
      // for types that need one word:
      //               word2, word1 -> word1, word1, word2
      // for types that need two words:
      //               word3, word2, word1 -> word1, word1, word3, word2
      //
      try {
        if(Type.BOOLEAN.equals(inType)) {
          if(booleanType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Boolean", "valueOf", "(Z)Ljava/lang/Boolean;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Boolean", "<init>", "(Z)V")))// For JDK < 5 (works also with newer JDKs)
            instructions.insert(new SWAP());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP_X1());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Boolean")));                  // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.BYTE.equals(inType)) {
          if(byteType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Byte", "valueOf", "(B)Ljava/lang/Byte;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Byte", "<init>", "(B)V")));    // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new SWAP());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP_X1());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Byte")));                    // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.CHAR.equals(inType)) {
          if(characterType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Character", "valueOf", "(C)Ljava/lang/Character;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Character", "<init>", "(C)V")))// For JDK < 5 (works also with newer JDKs)
            instructions.insert(new SWAP());                                    // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP_X1());                                    // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Character")));                  // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.DOUBLE.equals(inType)) {
          if(doubleType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Double", "valueOf", "(D)Ljava/lang/Double;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Double", "<init>", "(D)V")))// For JDK < 5 (works also with newer JDKs)
            instructions.insert(new POP2());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP2_X2());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP());                                    // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Double")));                  // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.FLOAT.equals(inType)) {
          if(floatType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Float", "valueOf", "(F)Ljava/lang/Float;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Float", "<init>", "(F)V")))// For JDK < 5 (works also with newer JDKs)
            instructions.insert(new SWAP());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP_X1());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Float")));                  // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.INT.equals(inType)) {
          if(integerType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Integer", "valueOf", "(I)Ljava/lang/Integer;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Integer", "<init>", "(I)V")))// For JDK < 5 (works also with newer JDKs)
            instructions.insert(new SWAP());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP_X1());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Integer")));                  // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.LONG.equals(inType)) {
          if(longType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Long", "valueOf", "(J)Ljava/lang/Long;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Long", "<init>", "(J)V")));    // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new POP2());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP2_X2());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP());                                    // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Long")));                    // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
        else if(Type.SHORT.equals(inType)) {
          if(shortType.isAssignmentCompatibleWith(outType)) {
            //instructions.insert(new INVOKESTATIC(cpGen.addMethodref("java.lang.Short", "valueOf", "(S)Ljava/lang/Short;")));  // Only for JDK > 5
            instructions.insert(new INVOKESPECIAL(cpGen.addMethodref("java.lang.Short", "<init>", "(S)V")))// For JDK < 5 (works also with newer JDKs)
            instructions.insert(new SWAP());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new DUP_X1());                                  // For JDK < 5 (works also with newer JDKs)
            instructions.insert(new NEW(cpGen.addClass("java.lang.Short")));                  // For JDK < 5 (works also with newer JDKs)
            return;
          }
        }
          throw new IllegalProceedUsageException("cannot inboxing from " + inType + " to " + outType);
      } catch(ClassNotFoundException e) {throw new JVMAIRuntimeException(e.getMessage());}
    }
  }
View Full Code Here

TOP

Related Classes of ch.ethz.jvmai.JVMAIRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.