static {
   try {
     MetaAccessProvider runtime = Graal.getRequiredCapability(MetaAccessProvider.class);
     LOCALS_FIELD = runtime.lookupJavaField(FrameWithoutBoxing.class.getDeclaredField("locals"));
     PRIMITIVELOCALS_FIELD =
         runtime.lookupJavaField(FrameWithoutBoxing.class.getDeclaredField("primitiveLocals"));
     TAGS_FIELD = runtime.lookupJavaField(FrameWithoutBoxing.class.getDeclaredField("tags"));
   } catch (NoSuchFieldException e) {
     throw new RuntimeException(e);
   }
 }
Example #2
0
  protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
    ResolvedJavaMethod method = codeCache.lookupJavaMethod(m);
    RegisterConfig registerConfig = codeCache.lookupRegisterConfig();
    CallingConvention cc =
        CodeUtil.getCallingConvention(codeCache, CallingConvention.Type.JavaCallee, method, false);

    CompilationResult compResult = new CompilationResult();
    Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
    compResult.setTargetCode(codeBuffer.close(true), codeBuffer.position());

    InstalledCode code = codeCache.addMethod(method, compResult);

    DisassemblerProvider dis = Graal.getRuntime().getCapability(DisassemblerProvider.class);
    if (dis != null) {
      String disasm = dis.disassemble(code);
      Assert.assertTrue(code.toString(), disasm == null || disasm.length() > 0);
    }
    return code;
  }
Example #3
0
  public TypeUniverse() {
    Providers providers =
        Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders();
    metaAccess = providers.getMetaAccess();
    constantReflection = providers.getConstantReflection();
    snippetReflection = Graal.getRequiredCapability(SnippetReflectionProvider.class);
    Unsafe theUnsafe = null;
    try {
      theUnsafe = Unsafe.getUnsafe();
    } catch (Exception e) {
      try {
        Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
        theUnsafeField.setAccessible(true);
        theUnsafe = (Unsafe) theUnsafeField.get(null);
      } catch (Exception e1) {
        throw (InternalError) new InternalError("unable to initialize unsafe").initCause(e1);
      }
    }
    unsafe = theUnsafe;

    Class<?>[] initialClasses = {
      void.class,
      boolean.class,
      byte.class,
      short.class,
      char.class,
      int.class,
      float.class,
      long.class,
      double.class,
      Object.class,
      Class.class,
      ClassLoader.class,
      String.class,
      Serializable.class,
      Cloneable.class,
      Test.class,
      TestMetaAccessProvider.class,
      List.class,
      Collection.class,
      Map.class,
      Queue.class,
      HashMap.class,
      LinkedHashMap.class,
      IdentityHashMap.class,
      AbstractCollection.class,
      AbstractList.class,
      ArrayList.class
    };
    for (Class<?> c : initialClasses) {
      addClass(c);
    }
    for (Field f : Constant.class.getDeclaredFields()) {
      int mods = f.getModifiers();
      if (f.getType() == Constant.class
          && Modifier.isPublic(mods)
          && Modifier.isStatic(mods)
          && Modifier.isFinal(mods)) {
        try {
          Constant c = (Constant) f.get(null);
          if (c != null) {
            constants.add(c);
          }
        } catch (Exception e) {
        }
      }
    }
    for (Class<?> c : classes) {
      if (c != void.class && !c.isArray()) {
        constants.add(snippetReflection.forObject(Array.newInstance(c, 42)));
      }
    }
    constants.add(snippetReflection.forObject(new ArrayList<>()));
    constants.add(snippetReflection.forObject(new IdentityHashMap<>()));
    constants.add(snippetReflection.forObject(new LinkedHashMap<>()));
    constants.add(snippetReflection.forObject(new TreeMap<>()));
    constants.add(snippetReflection.forObject(new ArrayDeque<>()));
    constants.add(snippetReflection.forObject(new LinkedList<>()));
    constants.add(snippetReflection.forObject("a string"));
    constants.add(snippetReflection.forObject(42));
    constants.add(snippetReflection.forObject(String.class));
    constants.add(snippetReflection.forObject(String[].class));
  }
Example #4
0
 public AssemblerTest() {
   this.codeCache = Graal.getRequiredCapability(CodeCacheProvider.class);
 }