comparison 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
comparison
equal deleted inserted replaced
12058:ccb4f2af2319 12355:cefad50507d8
312 } 312 }
313 } 313 }
314 } 314 }
315 } 315 }
316 316
317 void os::init_before_ergo() {
318 // We need to initialize large page support here because ergonomics takes some
319 // decisions depending on large page support and the calculated large page size.
320 large_page_init();
321 }
317 322
318 void os::signal_init() { 323 void os::signal_init() {
319 if (!ReduceSignalUsage) { 324 if (!ReduceSignalUsage) {
320 // Setup JavaThread for processing signals 325 // Setup JavaThread for processing signals
321 EXCEPTION_MARK; 326 EXCEPTION_MARK;
439 } 444 }
440 } 445 }
441 } 446 }
442 } 447 }
443 return _native_java_library; 448 return _native_java_library;
449 }
450
451 /*
452 * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
453 * If check_lib == true then we are looking for an
454 * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
455 * this library is statically linked into the image.
456 * If check_lib == false then we will look for the appropriate symbol in the
457 * executable if agent_lib->is_static_lib() == true or in the shared library
458 * referenced by 'handle'.
459 */
460 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
461 const char *syms[], size_t syms_len) {
462 assert(agent_lib != NULL, "sanity check");
463 const char *lib_name;
464 void *handle = agent_lib->os_lib();
465 void *entryName = NULL;
466 char *agent_function_name;
467 size_t i;
468
469 // If checking then use the agent name otherwise test is_static_lib() to
470 // see how to process this lookup
471 lib_name = ((check_lib || agent_lib->is_static_lib()) ? agent_lib->name() : NULL);
472 for (i = 0; i < syms_len; i++) {
473 agent_function_name = build_agent_function_name(syms[i], lib_name, agent_lib->is_absolute_path());
474 if (agent_function_name == NULL) {
475 break;
476 }
477 entryName = dll_lookup(handle, agent_function_name);
478 FREE_C_HEAP_ARRAY(char, agent_function_name, mtThread);
479 if (entryName != NULL) {
480 break;
481 }
482 }
483 return entryName;
484 }
485
486 // See if the passed in agent is statically linked into the VM image.
487 bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[],
488 size_t syms_len) {
489 void *ret;
490 void *proc_handle;
491 void *save_handle;
492
493 assert(agent_lib != NULL, "sanity check");
494 if (agent_lib->name() == NULL) {
495 return false;
496 }
497 proc_handle = get_default_process_handle();
498 // Check for Agent_OnLoad/Attach_lib_name function
499 save_handle = agent_lib->os_lib();
500 // We want to look in this process' symbol table.
501 agent_lib->set_os_lib(proc_handle);
502 ret = find_agent_function(agent_lib, true, syms, syms_len);
503 if (ret != NULL) {
504 // Found an entry point like Agent_OnLoad_lib_name so we have a static agent
505 agent_lib->set_valid();
506 agent_lib->set_static_lib(true);
507 return true;
508 }
509 agent_lib->set_os_lib(save_handle);
510 return false;
444 } 511 }
445 512
446 // --------------------- heap allocation utilities --------------------- 513 // --------------------- heap allocation utilities ---------------------
447 514
448 char *os::strdup(const char *str, MEMFLAGS flags) { 515 char *os::strdup(const char *str, MEMFLAGS flags) {
1425 } 1492 }
1426 } 1493 }
1427 return result; 1494 return result;
1428 } 1495 }
1429 1496
1430 // Read file line by line, if line is longer than bsize,
1431 // skip rest of line.
1432 int os::get_line_chars(int fd, char* buf, const size_t bsize){
1433 size_t sz, i = 0;
1434
1435 // read until EOF, EOL or buf is full
1436 while ((sz = (int) read(fd, &buf[i], 1)) == 1 && i < (bsize-2) && buf[i] != '\n') {
1437 ++i;
1438 }
1439
1440 if (buf[i] == '\n') {
1441 // EOL reached so ignore EOL character and return
1442
1443 buf[i] = 0;
1444 return (int) i;
1445 }
1446
1447 buf[i+1] = 0;
1448
1449 if (sz != 1) {
1450 // EOF reached. if we read chars before EOF return them and
1451 // return EOF on next call otherwise return EOF
1452
1453 return (i == 0) ? -1 : (int) i;
1454 }
1455
1456 // line is longer than size of buf, skip to EOL
1457 char ch;
1458 while (read(fd, &ch, 1) == 1 && ch != '\n') {
1459 // Do nothing
1460 }
1461
1462 // return initial part of line that fits in buf.
1463 // If we reached EOF, it will be returned on next call.
1464
1465 return (int) i;
1466 }
1467
1468 void os::SuspendedThreadTask::run() { 1497 void os::SuspendedThreadTask::run() {
1469 assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this"); 1498 assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this");
1470 internal_do_task(); 1499 internal_do_task();
1471 _done = true; 1500 _done = true;
1472 } 1501 }