Example #1
0
void RuntimeBlob::trace_new_stub(RuntimeBlob* stub, const char* name1, const char* name2) {
  // Do not hold the CodeCache lock during name formatting.
  assert(!CodeCache_lock->owned_by_self(), "release CodeCache before registering the stub");

  if (stub != NULL) {
    char stub_id[256];
    assert(strlen(name1) + strlen(name2) < sizeof(stub_id), "");
    jio_snprintf(stub_id, sizeof(stub_id), "%s%s", name1, name2);
    if (PrintStubCode) {
      ttyLocker ttyl;
      tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, (intptr_t) stub);
      Disassembler::decode(stub->code_begin(), stub->code_end());
      tty->cr();
    }
    Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());

    if (JvmtiExport::should_post_dynamic_code_generated()) {
      const char* stub_name = name2;
      if (name2[0] == '\0')  stub_name = name1;
      JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
    }
  }

  // Track memory usage statistic after releasing CodeCache_lock
  MemoryService::track_code_cache_memory_usage();
}
Example #2
0
void HashtableTextDump::corrupted(const char *p, const char* msg) {
  char info[100];
  jio_snprintf(info, sizeof(info),
               "%s. Corrupted at line %d (file pos %d)",
               msg, _line_no, (int)(p - _base));
  quit(info, _filename);
}
OSRAdapter* OSRAdapter::new_osr_adapter(CodeBuffer* cb,	OopMapSet *oop_maps,
                                        int frame_size, int returning_fp_entry_offset) {
  unsigned int size = allocation_size(cb, sizeof(OSRAdapter));
  OSRAdapter* osr_adapter = NULL;
  {
    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
    osr_adapter = new (size) OSRAdapter(cb, oop_maps, size, frame_size, returning_fp_entry_offset);
  }

  // We do not need to hold the CodeCache lock during name formatting.
  if (osr_adapter != NULL) {
    char blob_id[256];
    jio_snprintf(blob_id, sizeof(blob_id), "OSRAdapter@" PTR_FORMAT, osr_adapter->instructions_begin());
    VTune::register_stub(blob_id, osr_adapter->instructions_begin(), osr_adapter->instructions_end());
    Forte::register_stub(blob_id, osr_adapter->instructions_begin(), osr_adapter->instructions_end());

    // notify JVMTI profiler about this OSR
    if (JvmtiExport::should_post_dynamic_code_generated()) {
      JvmtiExport::post_dynamic_code_generated("OSRAdapter", osr_adapter->instructions_begin(),
					       osr_adapter->instructions_end());
    }
  }

  return osr_adapter;
}
Example #4
0
// Test parsing a bunch of valid file output options
TEST_VM(LogFileOutput, parse_valid) {
  const char* valid_options[] = {
    "", "filecount=10", "filesize=512",
    "filecount=11,filesize=256",
    "filesize=256,filecount=11",
    "filesize=0", "filecount=1",
    "filesize=1m", "filesize=1M",
    "filesize=1k", "filesize=1G"
  };

  // Override LogOutput's vm_start time to get predictable file name
  LogFileOutput::set_file_name_parameters(0);
  char expected_filename[1 * K];
  int ret = jio_snprintf(expected_filename, sizeof(expected_filename),
                         "testlog.pid%d.1970-01-01_01-00-00.log",
                         os::current_process_id());
  ASSERT_GT(ret, 0) << "Buffer too small";

  for (size_t i = 0; i < ARRAY_SIZE(valid_options); i++) {
    ResourceMark rm;
    stringStream ss;
    {
      LogFileOutput fo(name);
      EXPECT_STREQ(name, fo.name());
      EXPECT_TRUE(fo.initialize(valid_options[i], &ss))
        << "Did not accept valid option(s) '" << valid_options[i] << "': " << ss.as_string();
    }
    remove(expected_filename);
  }
}
void VMError::show_message_box(char *buf, int buflen) {
  bool yes;
  do {
    error_string(buf, buflen);
    int len = (int)strlen(buf);
    char *p = &buf[len];

    jio_snprintf(p, buflen - len,
               "\n\n"
               "Do you want to debug the problem?\n\n"
               "To debug, attach Visual Studio to process %d; then switch to thread 0x%x\n"
               "Select 'Yes' to launch Visual Studio automatically (PATH must include msdev)\n"
               "Otherwise, select 'No' to abort...",
               os::current_process_id(), os::current_thread_id());

    yes = os::message_box("Unexpected Error", buf) != 0;

    if (yes) {
      // yes, user asked VM to launch debugger
      //
      // os::breakpoint() calls DebugBreak(), which causes a breakpoint
      // exception. If VM is running inside a debugger, the debugger will
      // catch the exception. Otherwise, the breakpoint exception will reach
      // the default windows exception handler, which can spawn a debugger and
      // automatically attach to the dying VM.
      os::breakpoint();
      yes = false;
    }
  } while (yes);
}
Example #6
0
NMT_TrackingLevel MemTracker::init_tracking_level() {
  NMT_TrackingLevel level = NMT_off;
  char buf[64];
  jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id());
  const char *nmt_option = ::getenv(buf);
  if (nmt_option != NULL) {
    if (strcmp(nmt_option, "summary") == 0) {
      level = NMT_summary;
    } else if (strcmp(nmt_option, "detail") == 0) {
      level = NMT_detail;
    } else if (strcmp(nmt_option, "off") != 0) {
      // The option value is invalid
      _is_nmt_env_valid = false;
    }

    // Remove the environment variable to avoid leaking to child processes
    os::unsetenv(buf);
  }

  // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
  // but it is benign, the results are the same.
  ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);

  if (!MallocTracker::initialize(level) ||
      !VirtualMemoryTracker::initialize(level)) {
    level = NMT_off;
  }
  return level;
}
Example #7
0
ageTable::ageTable(bool global) {

  clear();

  if (UsePerfData && global) {

    ResourceMark rm;
    EXCEPTION_MARK;

    const char* agetable_ns = "generation.0.agetable";
    const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes");

    for(int age = 0; age < table_size; age ++) {
      char age_name[10];
      jio_snprintf(age_name, sizeof(age_name), "%2.2d", age);
      const char* cname = PerfDataManager::counter_name(bytes_ns, age_name);
      _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname,
                                                          PerfData::U_Bytes,
                                                          CHECK);
    }

    const char* cname = PerfDataManager::counter_name(agetable_ns, "size");
    PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,
                                     table_size, CHECK);
  }
}
 GCCauseString& append(const char* str) {
   int res = jio_snprintf(_buffer + _position, _length - _position, "%s", str);
   _position += res;
   assert(res >= 0 && _position <= _length,
     err_msg("Need to increase the buffer size in GCCauseString? %d", res));
   return *this;
 }
// Prepare _all_decorators to contain the full list of decorators (comma separated)
void LogConfigurationTest::SetUpTestCase() {
  char *pos = _all_decorators;
  for (size_t i = 0; i < LogDecorators::Count; i++) {
    pos += jio_snprintf(pos, sizeof(_all_decorators) - (pos - _all_decorators), "%s%s",
                        (i == 0 ? "" : ","),
                        LogDecorators::name(static_cast<LogDecorators::Decorator>(i)));
  }
}
// Test basic command line parsing & configuration
TEST_VM_F(LogConfigurationTest, parse_command_line_arguments) {
  // Prepare a command line for logging*=debug on stderr with all decorators
  int ret;
  char buf[256];
  ret = jio_snprintf(buf, sizeof(buf), "logging*=debug:stderr:%s", _all_decorators);
  ASSERT_NE(-1, ret);

  bool success = LogConfiguration::parse_command_line_arguments(buf);
  EXPECT_TRUE(success) << "Error parsing valid command line arguments '" << buf << "'";
  // Ensure the new configuration applied
  EXPECT_TRUE(is_described("logging=debug"));
  EXPECT_TRUE(is_described(_all_decorators));

  // Test the configuration of file outputs as well
  ret = jio_snprintf(buf, sizeof(buf), ":%s", TestLogFileName);
  ASSERT_NE(-1, ret);
  EXPECT_TRUE(LogConfiguration::parse_command_line_arguments(buf));
}
static char *fullPath(JNIEnv *env, char *part, char *full) {
    char **tmp;
    struct stat b;
    int ret;
    /*
     * If the filename we want to exec has any slashes in it then
     * we shouldn't do a path search, as in /foo ./foo or foo/bar.
     */
    if ((strchr(part, '/') == NULL) && PATH) {
	for (tmp = PATH; *tmp; tmp++) {
	    strcpy(full, *tmp);
	    /*
	     * empty path elements are like '.' so we don't want to append
	     * a slash to them.  Otherwise foo becomes /foo.
	     */
	    if (full[0] != '\0') {
		strcat(full, "/");
	    }
	    strcat(full, part);
	    ret = statExecutable(full, &b);
	    if (ret == -1) { /* doesn't exist */
		continue;
	    } else if (ret == -2) { /* can't execute */
		continue;    /* bug 4199993 - got to keep searching. */
	    } else {
		return full;
	    }
	}
    } else if (!(ret = statExecutable(part, &b))) {
	/* always copy value to be returned so `part' may always be freed
	 * after call (if needed) */
	strcpy(full, part);
	return full;
    } else if (ret == -2) { /* cannot execute */
	jio_snprintf(full, MAXPATHLEN, "%s: cannot execute", part);
	JNU_ThrowIOException(env, full);
	return 0;
    }

    /* not found if we got here */
    jio_snprintf(full, MAXPATHLEN, "%s: not found", part);
    JNU_ThrowIOException(env, full);
    return 0;
}
PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
void Flag::print_on(outputStream* st, bool withComments) {
  // Don't print notproduct and develop flags in a product build.
  if (is_constant_in_binary()) {
    return;
  }

  st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' '));

  if (is_bool()) {
    st->print("%-16s", get_bool() ? "true" : "false");
  }
  if (is_intx()) {
    st->print("%-16ld", get_intx());
  }
  if (is_uintx()) {
    st->print("%-16lu", get_uintx());
  }
  if (is_uint64_t()) {
    st->print("%-16lu", get_uint64_t());
  }
  if (is_double()) {
    st->print("%-16f", get_double());
  }
  if (is_ccstr()) {
    const char* cp = get_ccstr();
    if (cp != NULL) {
      const char* eol;
      while ((eol = strchr(cp, '\n')) != NULL) {
        char format_buffer[FORMAT_BUFFER_LEN];
        size_t llen = pointer_delta(eol, cp, sizeof(char));
        jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
            "%%." SIZE_FORMAT "s", llen);
PRAGMA_DIAG_PUSH
PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
        st->print(format_buffer, cp);
PRAGMA_DIAG_POP
        st->cr();
        cp = eol+1;
        st->print("%5s %-35s += ", "", _name);
      }
      st->print("%-16s", cp);
    }
    else st->print("%-16s", "");
  }

  st->print("%-20s", " ");
  print_kind(st);

  if (withComments) {
#ifndef PRODUCT
    st->print("%s", _doc);
#endif
  }
  st->cr();
}
Example #13
0
void LogFileOutput::set_file_name_parameters(jlong vm_start_time) {
  int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id());
  assert(res > 0, "PID buffer too small");

  struct tm local_time;
  time_t utc_time = vm_start_time / 1000;
  os::localtime_pd(&utc_time, &local_time);
  res = (int)strftime(_vm_start_time_str, sizeof(_vm_start_time_str), TimestampFormat, &local_time);
  assert(res > 0, "VM start time buffer too small.");
}
Example #14
0
// Test for overflows with filesize
TEST_VM(LogFileOutput, filesize_overflow) {
  char buf[256];
  int ret = jio_snprintf(buf, sizeof(buf), "filesize=" SIZE_FORMAT "K", SIZE_MAX);
  ASSERT_GT(ret, 0) << "Buffer too small";

  ResourceMark rm;
  stringStream ss;
  LogFileOutput fo(name);
  EXPECT_FALSE(fo.initialize(buf, &ss)) << "Accepted filesize that overflows";
}
// Test reconfiguration of the selected decorators for an output
TEST_VM_F(LogConfigurationTest, reconfigure_decorators) {
  // Configure stderr with all decorators
  set_log_config("stderr", "all=off", _all_decorators);
  char buf[256];
  int ret = jio_snprintf(buf, sizeof(buf), "#1: stderr all=off %s", _all_decorators);
  ASSERT_NE(-1, ret);
  EXPECT_TRUE(is_described(buf)) << "'" << buf << "' not described after reconfiguration";

  // Now reconfigure logging on stderr with no decorators
  set_log_config("stderr", "all=off", "none");
  EXPECT_TRUE(is_described("#1: stderr all=off \n")) << "Expecting no decorators";
}
Example #16
0
int LogTagSet::label(char* buf, size_t len, const char* separator) const {
  int tot_written = 0;
  for (size_t i = 0; i < _ntags; i++) {
    int written = jio_snprintf(buf + tot_written, len - tot_written, "%s%s",
                               (i == 0 ? "" : separator),
                               LogTag::name(_tag[i]));
    if (written < 0) {
      return -1;
    }
    tot_written += written;
  }
  return tot_written;
}
Example #17
0
ClassClass *LoadClassLocally(char *name)
{
	extern char *extra_class_path;
    ClassClass *cb = 0;
    cpe_t **cpp;

    if (name[0] == DIR_SEPARATOR || name[0] == SIGNATURE_ARRAY) 
	return 0;

    for (cpp = sysGetClassPath(); cpp && *cpp != 0; cpp++) {
	cpe_t *cpe = *cpp;
	char path[255];
	if (cpe->type == CPE_DIR) {
	    if (jio_snprintf(path, sizeof(path), 
			     "%s%c%s." JAVAOBJEXT, cpe->u.dir,
			     LOCAL_DIR_SEPARATOR, name) == -1) {
		return 0;
	    }
	    if (cb = LoadClassFromFile(sysNativePath(path), cpe->u.dir, name)) {
		return cb;
	    }
	}
	
    }
	if (extra_class_path) {
		char path[255];
	    if (jio_snprintf(path, sizeof(path), 
			     "%s%c%s." JAVAOBJEXT, extra_class_path,
			     LOCAL_DIR_SEPARATOR, name) == -1) {
			return 0;
		}
	    if (cb = LoadClassFromFile(sysNativePath(path), extra_class_path, name)) {
			return cb;
		}
	}
    return cb;
}
// Get custom message for this locked flag, or return NULL if
// none is available.
void Flag::get_locked_message(char* buf, int buflen) const {
  buf[0] = '\0';
  if (is_diagnostic() && !is_unlocked()) {
    jio_snprintf(buf, buflen, "Error: VM option '%s' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.\n",
                 _name);
    return;
  }
  if (is_experimental() && !is_unlocked()) {
    jio_snprintf(buf, buflen, "Error: VM option '%s' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.\n",
                 _name);
    return;
  }
  if (is_develop() && is_product_build()) {
    jio_snprintf(buf, buflen, "Error: VM option '%s' is develop and is available only in debug version of VM.\n",
                 _name);
    return;
  }
  if (is_notproduct() && is_product_build()) {
    jio_snprintf(buf, buflen, "Error: VM option '%s' is notproduct and is available only in debug version of VM.\n",
                 _name);
    return;
  }
  get_locked_message_ext(buf, buflen);
}
bool MachODecoder::demangle(const char* symbol, char *buf, int buflen) {
  int   status;
  char* result;
  size_t size = (size_t)buflen;
  // Don't pass buf to __cxa_demangle. In case of the 'buf' is too small,
  // __cxa_demangle will call system "realloc" for additional memory, which
  // may use different malloc/realloc mechanism that allocates 'buf'.
  if ((result = abi::__cxa_demangle(symbol, NULL, NULL, &status)) != NULL) {
    jio_snprintf(buf, buflen, "%s", result);
      // call c library's free
      ::free(result);
      return true;
  }
  return false;
}
TEST(LogTagSetDescriptions, describe) {
  for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
    char expected[1 * K];
    d->tagset->label(expected, sizeof(expected), "+");
    jio_snprintf(expected + strlen(expected),
                 sizeof(expected) - strlen(expected),
                 ": %s", d->descr);

    ResourceMark rm;
    stringStream stream;
    LogConfiguration::describe(&stream);
    EXPECT_PRED2(string_contains_substring, stream.as_string(), expected)
      << "missing log tag set descriptions in LogConfiguration::describe";
  }
}
Example #21
0
// Try to find the next number that should be used for file rotation.
// Return UINT_MAX on error.
static uint next_file_number(const char* filename,
                             uint number_of_digits,
                             uint filecount,
                             outputStream* errstream) {
  bool found = false;
  uint next_num = 0;

  // len is filename + dot + digits + null char
  size_t len = strlen(filename) + number_of_digits + 2;
  char* archive_name = NEW_C_HEAP_ARRAY(char, len, mtLogging);
  char* oldest_name = NEW_C_HEAP_ARRAY(char, len, mtLogging);

  for (uint i = 0; i < filecount; i++) {
    int ret = jio_snprintf(archive_name, len, "%s.%0*u",
                           filename, number_of_digits, i);
    assert(ret > 0 && static_cast<size_t>(ret) == len - 1,
           "incorrect buffer length calculation");

    if (file_exists(archive_name) && !is_regular_file(archive_name)) {
      // We've encountered something that's not a regular file among the
      // possible file rotation targets. Fail immediately to prevent
      // problems later.
      errstream->print_cr("Possible rotation target file '%s' already exists "
                          "but is not a regular file.", archive_name);
      next_num = UINT_MAX;
      break;
    }

    // Stop looking if we find an unused file name
    if (!file_exists(archive_name)) {
      next_num = i;
      found = true;
      break;
    }

    // Keep track of oldest existing log file
    if (!found
        || os::compare_file_modified_times(oldest_name, archive_name) > 0) {
      strcpy(oldest_name, archive_name);
      next_num = i;
      found = true;
    }
  }

  FREE_C_HEAP_ARRAY(char, oldest_name);
  FREE_C_HEAP_ARRAY(char, archive_name);
  return next_num;
}
TEST(LogTagSetDescriptions, command_line_help) {
  const char* filename = "logtagset_descriptions";
  FILE* fp = fopen(filename, "w+");
  ASSERT_NE((void*)NULL, fp);
  LogConfiguration::print_command_line_help(fp);
  fclose(fp);

  for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
    char expected[1 * K];
    d->tagset->label(expected, sizeof(expected), "+");
    jio_snprintf(expected + strlen(expected),
                 sizeof(expected) - strlen(expected),
                 ": %s", d->descr);

    EXPECT_TRUE(file_contains_substring(filename, expected)) << "missing log tag set descriptions in -Xlog:help output";
  }
  delete_file(filename);
}
Example #23
0
void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
  Label L;
  BLOCK_COMMENT("verify_ref_kind {");
  __ movl(temp, Address(member_reg, NONZERO(java_lang_invoke_MemberName::flags_offset_in_bytes())));
  __ shrl(temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT);
  __ andl(temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK);
  __ cmpl(temp, ref_kind);
  __ jcc(Assembler::equal, L);
  { char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal);
    jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind);
    if (ref_kind == JVM_REF_invokeVirtual ||
        ref_kind == JVM_REF_invokeSpecial)
      // could do this for all ref_kinds, but would explode assembly code size
      trace_method_handle(_masm, buf);
    __ STOP(buf);
  }
  BLOCK_COMMENT("} verify_ref_kind");
  __ bind(L);
}
bool ElfStringTable::string_at(int pos, char* buf, int buflen) {
  if (NullDecoder::is_error(m_status)) {
    return false;
  }
  if (m_table != NULL) {
    jio_snprintf(buf, buflen, "%s", (const char*)(m_table + pos));
    return true;
  } else {
    long cur_pos = ftell(m_file);
    if (cur_pos == -1 ||
      fseek(m_file, m_shdr.sh_offset + pos, SEEK_SET) ||
      fread(buf, 1, buflen, m_file) <= 0 ||
      fseek(m_file, cur_pos, SEEK_SET)) {
      m_status = NullDecoder::file_invalid;
      return false;
    }
    return true;
  }
}
Example #25
0
void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
  Label L;
  BLOCK_COMMENT("verify_ref_kind {");
  __ load_sized_value(temp, NONZERO(java_lang_invoke_MemberName::flags_offset_in_bytes()), member_reg,
                      sizeof(u4), /*is_signed*/ false);
  // assert(sizeof(u4) == sizeof(java.lang.invoke.MemberName.flags), "");
  __ srwi( temp, temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT);
  __ andi(temp, temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK);
  __ cmpwi(CCR1, temp, ref_kind);
  __ beq(CCR1, L);
  { char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal);
    jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind);
    if (ref_kind == JVM_REF_invokeVirtual ||
        ref_kind == JVM_REF_invokeSpecial)
      // could do this for all ref_kinds, but would explode assembly code size
      trace_method_handle(_masm, buf);
    __ stop(buf);
  }
  BLOCK_COMMENT("} verify_ref_kind");
  __ BIND(L);
}
Example #26
0
Decoder::decoder_status Decoder::decode(address addr, char *buf, int buflen, int *offset) {
  assert(_initialized, "Decoder not yet initialized");
  if (_pfnSymGetSymFromAddr64 != NULL) {
    PIMAGEHLP_SYMBOL64 pSymbol;
    char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
    pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo;
    pSymbol->MaxNameLength = MAX_PATH;
    pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
    DWORD64 displacement;
    if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
      if (buf != NULL) {
        if (!demangle(pSymbol->Name, buf, buflen)) {
          jio_snprintf(buf, buflen, "%s", pSymbol->Name);
        }
      }
      if (offset != NULL) *offset = (int)displacement;
      return no_error;
    }
  }
  return helper_not_found;
}
Example #27
0
/*
 * Class:     sun_java2d_opengl_OGLContext
 * Method:    getOGLIdString
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_sun_java2d_opengl_OGLContext_getOGLIdString
(JNIEnv *env, jclass oglcc)
{
    char *vendor, *renderer, *version;
    char *pAdapterId;
    jobject ret = NULL;
    int len;

    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_getOGLIdString");

    vendor = (char*)j2d_glGetString(GL_VENDOR);
    if (vendor == NULL) {
        vendor = "Unknown Vendor";
    }
    renderer = (char*)j2d_glGetString(GL_RENDERER);
    if (renderer == NULL) {
        renderer = "Unknown Renderer";
    }
    version = (char*)j2d_glGetString(GL_VERSION);
    if (version == NULL) {
        version = "unknown version";
    }

    // 'vendor renderer (version)0'
    len = strlen(vendor) + 1 + strlen(renderer) + 1 + 1+strlen(version)+1 + 1;
    pAdapterId = malloc(len);
    if (pAdapterId != NULL) {

        jio_snprintf(pAdapterId, len, "%s %s (%s)", vendor, renderer, version);

        J2dTraceLn1(J2D_TRACE_VERBOSE, "  id=%s", pAdapterId);

        ret = JNU_NewStringPlatform(env, pAdapterId);

        free(pAdapterId);
    }

    return ret;
}
Example #28
0
void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {

  if (_libpath.value() == NULL) {
    output()->print_cr("JVMTI.agent_load dcmd needs library path.");
    return;
  }

  char *suffix = strrchr(_libpath.value(), '.');
  bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0);

  if (is_java_agent) {
    if (_option.value() == NULL) {
      JvmtiExport::load_agent_library("instrument", "false",
                                      _libpath.value(), output());
    } else {
      size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
      if (opt_len > 4096) {
        output()->print_cr("JVMTI agent attach failed: Options is too long.");
        return;
      }

      char *opt = (char *)os::malloc(opt_len, mtInternal);
      if (opt == NULL) {
        output()->print_cr("JVMTI agent attach failed: "
                           "Could not allocate %zu bytes for argument.",
                           opt_len);
        return;
      }

      jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
      JvmtiExport::load_agent_library("instrument", "false", opt, output());

      os::free(opt);
    }
  } else {
    JvmtiExport::load_agent_library(_libpath.value(), "true",
                                    _option.value(), output());
  }
}
Example #29
0
bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath)  {
  if (_pfnSymGetSymFromAddr64 != NULL) {
    PIMAGEHLP_SYMBOL64 pSymbol;
    char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
    pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo;
    pSymbol->MaxNameLength = MAX_PATH;
    pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
    DWORD64 displacement;
    if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
      if (buf != NULL) {
        if (demangle(pSymbol->Name, buf, buflen)) {
          jio_snprintf(buf, buflen, "%s", pSymbol->Name);
        }
      }
      if(offset != NULL) *offset = (int)displacement;
      return true;
    }
  }
  if (buf != NULL && buflen > 0) buf[0] = '\0';
  if (offset != NULL) *offset = -1;
  return false;
}
// Test split up log configuration arguments
TEST_VM_F(LogConfigurationTest, parse_log_arguments) {
  ResourceMark rm;
  stringStream ss;
  // Verify that it's possible to configure each individual tag
  for (size_t t = 1 /* Skip _NO_TAG */; t < LogTag::Count; t++) {
    const LogTagType tag = static_cast<LogTagType>(t);
    EXPECT_TRUE(LogConfiguration::parse_log_arguments("stdout", LogTag::name(tag), "", "", &ss));
  }
  // Same for each level
  for (size_t l = 0; l < LogLevel::Count; l++) {
    const LogLevelType level = static_cast<LogLevelType>(l);
    char expected_buf[256];
    int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "all=%s", LogLevel::name(level));
    ASSERT_NE(-1, ret);
    EXPECT_TRUE(LogConfiguration::parse_log_arguments("stderr", expected_buf, "", "", &ss));
  }
  // And for each decorator
  for (size_t d = 0; d < LogDecorators::Count; d++) {
    const LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
    EXPECT_TRUE(LogConfiguration::parse_log_arguments("#0", "", LogDecorators::name(decorator), "", &ss));
  }
}