Пример #1
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();
  }
  @Override
  public final RTValue f1S(final RTValue record, final RTExecutionContext $ec)
      throws CALExecutorException {
    $ec.incrementNMethodCalls();
    if (LECCMachineConfiguration.generateDebugCode()
        && $ec.isDebugProcessingNeeded(getQualifiedName())) {
      $ec.debugProcessing(getQualifiedName(), new RTValue[] {record});
    }

    final RTRecordValue recordValue = (RTRecordValue) record;

    for (int i = 0, nFields = recordValue.getNFields(); i < nFields; ++i) {
      final RTValue fieldValue = recordValue.getNthValue(i);
      final RTValue evaluatedFieldValue = fieldValue.evaluate($ec);
      if (fieldValue != evaluatedFieldValue) {
        // called for the side effect of collapsing any indirections. This is important for freeing
        // up space.
        recordValue.getNthValue(i);
      }
    }

    return recordValue;
  }
Пример #3
0
  /**
   * Look up the byte code definition of the named class.
   *
   * <p>Created: Mar 30, 2004
   *
   * @param className
   * @return - byte code for the class definition.
   */
  private byte[] lookupClassData(String className) {

    if (isJar(moduleParentLocator)) {
      String fileName;
      if (LECCMachineConfiguration.generateBytecode()) {
        fileName = className.replace('.', '/') + COMPRESSED_CLASS_FILE_EXTENSION;
      } else {
        fileName = className.replace('.', '/') + CLASS_FILE_EXTENSION;
      }
      return loadJarData((ProgramResourceLocator.File) moduleParentLocator, fileName);

    } else {

      ProgramResourceLocator.File fileLocator;
      if (LECCMachineConfiguration.generateBytecode()) {
        String extension =
            className.substring(className.lastIndexOf('.') + 1)
                + CALClassLoader.COMPRESSED_CLASS_FILE_EXTENSION;
        fileLocator = ((ProgramResourceLocator.Folder) moduleParentLocator).extendFile(extension);
      } else {
        String extension =
            className.substring(className.lastIndexOf('.') + 1)
                + CALClassLoader.CLASS_FILE_EXTENSION;
        fileLocator = ((ProgramResourceLocator.Folder) moduleParentLocator).extendFile(extension);
      }

      byte[] fileData = loadFileData(fileLocator);
      if (LECCMachineConfiguration.generateBytecode()) {
        if (fileData == null) {
          return null;
        }

        // uncompress the data..
        inflater.reset();
        inflater.setInput(fileData);

        // Reusing this baos should be ok, since its only other use is in loadFileData(), which
        // we've finished calling.
        ByteArrayOutputStream baos = threadLocalByteArrayOutputStream.get();
        baos.reset();

        try {
          // Reusing this bytearray should be ok, since its only other use is in loadFileData(),
          // which we've finished calling.
          byte[] buf = threadLocalByteArray.get();
          while (!inflater.finished()) {
            int len = inflater.inflate(buf);
            baos.write(buf, 0, len);
          }

        } catch (DataFormatException e) {
          // Can't read the compressed class..

          // return null;
          throw new IllegalStateException("Can't read compressed class: " + className);
        }

        return baos.toByteArray();

        // Not necessary to close the ByteArrayOutputStream.

      } else {
        // Source generator.
        return fileData;
      }
    }
  }