Mercurial > hg > truffle
diff src/share/vm/runtime/os.cpp @ 12355:cefad50507d8
Merge with hs25-b53
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 11 Oct 2013 10:38:03 +0200 |
parents | 6b0fd0964b87 179cd89fb279 |
children | d8041d695d19 |
line wrap: on
line diff
--- a/src/share/vm/runtime/os.cpp Thu Oct 10 18:26:22 2013 +0200 +++ b/src/share/vm/runtime/os.cpp Fri Oct 11 10:38:03 2013 +0200 @@ -314,6 +314,11 @@ } } +void os::init_before_ergo() { + // We need to initialize large page support here because ergonomics takes some + // decisions depending on large page support and the calculated large page size. + large_page_init(); +} void os::signal_init() { if (!ReduceSignalUsage) { @@ -443,6 +448,68 @@ return _native_java_library; } +/* + * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists. + * If check_lib == true then we are looking for an + * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if + * this library is statically linked into the image. + * If check_lib == false then we will look for the appropriate symbol in the + * executable if agent_lib->is_static_lib() == true or in the shared library + * referenced by 'handle'. + */ +void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib, + const char *syms[], size_t syms_len) { + assert(agent_lib != NULL, "sanity check"); + const char *lib_name; + void *handle = agent_lib->os_lib(); + void *entryName = NULL; + char *agent_function_name; + size_t i; + + // If checking then use the agent name otherwise test is_static_lib() to + // see how to process this lookup + lib_name = ((check_lib || agent_lib->is_static_lib()) ? agent_lib->name() : NULL); + for (i = 0; i < syms_len; i++) { + agent_function_name = build_agent_function_name(syms[i], lib_name, agent_lib->is_absolute_path()); + if (agent_function_name == NULL) { + break; + } + entryName = dll_lookup(handle, agent_function_name); + FREE_C_HEAP_ARRAY(char, agent_function_name, mtThread); + if (entryName != NULL) { + break; + } + } + return entryName; +} + +// See if the passed in agent is statically linked into the VM image. +bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[], + size_t syms_len) { + void *ret; + void *proc_handle; + void *save_handle; + + assert(agent_lib != NULL, "sanity check"); + if (agent_lib->name() == NULL) { + return false; + } + proc_handle = get_default_process_handle(); + // Check for Agent_OnLoad/Attach_lib_name function + save_handle = agent_lib->os_lib(); + // We want to look in this process' symbol table. + agent_lib->set_os_lib(proc_handle); + ret = find_agent_function(agent_lib, true, syms, syms_len); + if (ret != NULL) { + // Found an entry point like Agent_OnLoad_lib_name so we have a static agent + agent_lib->set_valid(); + agent_lib->set_static_lib(true); + return true; + } + agent_lib->set_os_lib(save_handle); + return false; +} + // --------------------- heap allocation utilities --------------------- char *os::strdup(const char *str, MEMFLAGS flags) { @@ -1427,44 +1494,6 @@ return result; } -// Read file line by line, if line is longer than bsize, -// skip rest of line. -int os::get_line_chars(int fd, char* buf, const size_t bsize){ - size_t sz, i = 0; - - // read until EOF, EOL or buf is full - while ((sz = (int) read(fd, &buf[i], 1)) == 1 && i < (bsize-2) && buf[i] != '\n') { - ++i; - } - - if (buf[i] == '\n') { - // EOL reached so ignore EOL character and return - - buf[i] = 0; - return (int) i; - } - - buf[i+1] = 0; - - if (sz != 1) { - // EOF reached. if we read chars before EOF return them and - // return EOF on next call otherwise return EOF - - return (i == 0) ? -1 : (int) i; - } - - // line is longer than size of buf, skip to EOL - char ch; - while (read(fd, &ch, 1) == 1 && ch != '\n') { - // Do nothing - } - - // return initial part of line that fits in buf. - // If we reached EOF, it will be returned on next call. - - return (int) i; -} - void os::SuspendedThreadTask::run() { assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this"); internal_do_task();