コード例 #1
0
inline ReturnOop ClassPathAccess::open_local_file(PathChar* path_name,
            Symbol* entry_symbol, const bool is_class_file JVM_TRAPS)
{
  const char separator_char = OsFile_separator_char;
  int pos = fn_strlen(path_name);

  path_name[pos++] = (PathChar)separator_char;
  for (int i=0; i<entry_symbol->length(); i++) {
      path_name[pos++] = (PathChar)entry_symbol->byte_at(i);
  }
  path_name[pos] = 0;
  if (is_class_file) {
    fn_strcat(path_name, FilePath::classfile_suffix);
  }

  if (separator_char != '/') {
    for(PathChar* tf = path_name; *tf; tf++) {
      if (*tf == (PathChar)'/') {
        *tf = (PathChar)separator_char;
      }
    }
  }

  OsFile_Handle handle = OsFile_open(path_name, "rb");
  if (handle == NULL) {
    return NULL;
  }

  int size = OsFile_length(handle);
  return FileDecoder::allocate(handle, 0, size, MUST_CLOSE_FILE
                               JVM_NO_CHECK_AT_BOTTOM);
}
コード例 #2
0
bool BufferedFile::open(const PathChar *name, const char *mode)
{
  set_file_pointer(OsFile_open(name, mode));
  OsFile_Handle fh = file_pointer();
  set_file_size(fh == NULL ? 0 : OsFile_length(fh));
  return (fh != NULL);
}
コード例 #3
0
ファイル: OS.cpp プロジェクト: hbao/phonemefeaturedevices
bool DefaultStream::has_log_file() {
  // Lazily create log file (at startup, LogVMOutput is false even
  // if +LogVMOutput is used, because the flags haven't been parsed yet
  if (LogVMOutput && _log_file == NULL) {
    _log_file = OsFile_open(__log_name, "w");
    __log_name[5]++;
  }
  return _log_file != NULL;
}
コード例 #4
0
ファイル: OsFile.cpp プロジェクト: weilinchina/JVM
bool OsFile_readFile(const char *filePath, JVM_BYTE *buf, size_t bufSize)
{
	if(filePath == NULL)
		return false;
	if(buf == NULL)
		return false;
	if(bufSize == 0)
		return false;

	JVM_FILE_HANDLE handle = OsFile_open(filePath, "rb");
	if(handle == NULL)
		return false;

	size_t readSize = OsFile_read(handle, buf, bufSize);
	OsFile_close(handle);

	return readSize == bufSize;
}
コード例 #5
0
ファイル: OS.cpp プロジェクト: hbao/phonemefeaturedevices
void DefaultStream::print_raw(const char* s) {
  JVMSPI_PrintRaw(s);

  // print to log file
  if (LogVMOutput && has_log_file()) {
    OsFile_write(_log_file, s, sizeof(char), jvm_strlen(s));
    //    OsFile_flush(_log_file);
    if (++__charcount == 200000000) {
      OsFile_flush(_log_file);
      JvmPathChar z = 'z';
      JvmPathChar a = 'a';
      __charcount = 0;
      OsFile_close(_log_file);
      _log_file = OsFile_open(__log_name, "w");
      if (__log_name[5] == z) {
        __log_name[5] = a;
      } else {
        __log_name[5]++;
      }
    }
  }


#if !defined(PRODUCT) || ENABLE_PROFILER || ENABLE_TTY_TRACE
  while (true) {
    char ch = *s++;
    if (ch == 0) {
      break;
    } else if (ch == '\n') {
      _position = 0;
    } else {
      _position += 1;
    }
  }
#endif
}
コード例 #6
0
// Create or retrieve a JarFileParser for the given JAR file.
// As a side effect, it might invalidate any previously obtained
// JarFileParser objects by closing their OsFile_handles.
ReturnOop JarFileParser::get(const JvmPathChar* jar_file_name1,
                             TypeArray * jar_file_name2,
                             bool enable_entry_cache JVM_TRAPS) {
  GUARANTEE((jar_file_name1 != NULL && jar_file_name2 == NULL) ||
            (jar_file_name1 == NULL && jar_file_name2 != NULL), "sanity");

  UsingFastOops fast_oops;
  JarFileParser::Fast parser = get_parser_from_cache(jar_file_name1,
                                                     jar_file_name2);
  if (parser.not_null()) {
    return parser;
  }

  if (jar_file_name1 && !OsFile_exists(jar_file_name1)) {
    return NULL;
  }
  if (jar_file_name2 && 
      !OsFile_exists((JvmPathChar *)jar_file_name2->byte_base_address())) {
    return NULL;
  }

  parser = Universe::new_mixed_oop(MixedOopDesc::Type_JarFileParser,
                                   JarFileParser::allocation_size(),
                                   JarFileParser::pointer_count()
                                   JVM_CHECK_0);
  TypeArray::Fast stored_name;
  if (jar_file_name1 != NULL) {
    size_t name_bytes = (fn_strlen(jar_file_name1)+1) * sizeof(JvmPathChar);
    stored_name = Universe::new_byte_array_raw(name_bytes JVM_CHECK_0);
    JvmPathChar *data = (JvmPathChar *)stored_name().byte_base_address();
    jvm_memcpy(data, jar_file_name1, name_bytes); // copy trailing NUL as well.
  } else {
    stored_name = jar_file_name2->obj();
  }


  BufferedFile::Fast bf = BufferedFile::allocate(JVM_SINGLE_ARG_CHECK_0);
  FileDescriptor::Fast desc = FileDescriptor::allocate(JVM_SINGLE_ARG_CHECK_0);

  OsFile_Handle fh = NULL;
  for (int pass=0; pass<2; pass++) {
    if (jar_file_name1) {
      fh = OsFile_open(jar_file_name1, "rb");
    } else {
      fh = OsFile_open((JvmPathChar *)jar_file_name2->byte_base_address(),
                       "rb");
    }
    if (fh != NULL) {
      break;
    }
    if (pass == 1 && fh == NULL) {
      // The system is running low on OsFile_Handles. Make sure we flush
      // the cache, and free all currently cached OsFile_Handles that belong
      // to other JAR files.
      flush_caches();
    }
  }
  if (fh == NULL) {
    return NULL;
  }

  desc().set_handle(fh);
  bf().set_file_pointer(fh);
  bf().set_file_size(fh == NULL ? 0 : OsFile_length(fh));
  parser().set_file_descriptor(&desc);
  parser().set_enable_entry_cache(enable_entry_cache);
  parser().set_pathname(&stored_name);
  parser().set_buffered_file(&bf);
  parser().set_timestamp(++_timestamp);

  if (!parser().find_end_of_central_header()) {
    // The jar file is corrupted. Stop parsing it.
    return NULL;
  }

  parser().save_parser_in_cache(JVM_SINGLE_ARG_MUST_SUCCEED);
  return parser;
}