Пример #1
0
  private CALClassLoader(
      ProgramResourceRepository resourceRepository,
      ProgramResourceLocator moduleParentLocator,
      ClassLoader parent,
      LECCModule module,
      List<LECCModule> dependeeModules) {
    super(parent);
    this.moduleParentLocator = moduleParentLocator;
    this.resourceRepository = resourceRepository;
    this.module = module;

    // Note: synchronization is unnecessary, as the table is only modified in the constructor.
    dependeeModuleLoaders = new HashMap<ModuleName, CALClassLoader>();

    ModuleName moduleName = module.getName();
    for (int i = 0, nDependeeModules = dependeeModules.size(); i < nDependeeModules; ++i) {
      LECCModule m = dependeeModules.get(i);
      if (m.getName().equals(moduleName)) {
        continue;
      }

      // m.getClassLoader() returns the adjunct classloader...
      CALClassLoader mcl = (CALClassLoader) m.getClassLoader().getParent();
      dependeeModuleLoaders.put(mcl.getModuleName(), mcl);
    }

    this.adjunctLoader = false;
    adjunctClasses = Collections.<String>emptySet();
  }
Пример #2
0
  /** @return whether class data should be looked up from the repository. */
  private boolean shouldLookupClassData() {
    // If we're using a dynamic runtime, never for the adjunct loader.
    // Otherwise, whether module.shouldLookupClassData() returns true.
    if (adjunctLoader && !LECCMachineConfiguration.isLeccRuntimeStatic()) {
      return false;
    }

    return module.shouldLookupClassData();
  }
Пример #3
0
  /*
   * @implementation
   * If you modify this method, you should also modify the related method
   * StandaloneJarBuilder.getStartPointInstanceJavaExpression
   */
  RTValue getStartPointInstance(
      String className, MachineFunction mf, RTExecutionContext executionContext)
      throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
          InvocationTargetException, NoSuchFieldException {

    if (mf == null) {
      throw new NullPointerException(
          "Invalid MachineFunction in CALClassLoader.getStartPointInstance() for "
              + className
              + ".");
    }
    Class<?> c = loadClass(className);

    if (mf.isDataConstructor()) {
      // This is a data constructor.
      // Get the static 'make' method.
      Method m = c.getMethod("make", new Class[] {});
      return (RTValue) m.invoke(null, new Object[] {});
    }

    FunctionGroupInfo fgi = module.getFunctionGroupInfo(mf);
    if (fgi == null) {
      throw new NullPointerException(
          "Invalid FunctionGroupInfo in CALClassLoader.getStartPointInstance() for "
              + mf.getQualifiedName()
              + ".");
    }

    if (mf.getArity() == 0) {
      // Get the static 'make' method.
      if (fgi.getNCAFs() + fgi.getNZeroArityFunctions() <= 1) {
        Method m = c.getMethod("make", new Class[] {RTExecutionContext.class});
        return (RTValue) m.invoke(null, new Object[] {executionContext});
      } else {
        Method m = c.getMethod("make", new Class[] {int.class, RTExecutionContext.class});
        int functionIndex = fgi.getFunctionIndex(mf.getName());
        return (RTValue)
            m.invoke(null, new Object[] {Integer.valueOf(functionIndex), executionContext});
      }
    }

    // Access the static instance field.
    String instanceFieldName = CALToJavaNames.getInstanceFieldName(mf.getQualifiedName(), module);
    Field field = c.getField(instanceFieldName);

    return (RTValue) field.get(null);
  }
Пример #4
0
 /** @return the name of the module for which this classloader is responsible. */
 public ModuleName getModuleName() {
   return module.getName();
 }
Пример #5
0
 @Override
 public String toString() {
   return "CALClassLoader for " + module.getName() + (adjunctLoader ? " adjuncts" : "");
 }