comparison src/os/solaris/vm/os_solaris.cpp @ 89:b97de546208e

6671882: memory access after free in solaris/vm/os_solaris.cpp Summary: Corrected the wrong memory access problem and made some minor clean ups Reviewed-by: dholmes, jcoomes
author xlu
date Thu, 03 Apr 2008 12:21:06 -0700
parents 82db0859acbe
children fcbfc50865ab
comparison
equal deleted inserted replaced
80:092ea87cc974 89:b97de546208e
4389 // since setting native thread priorities is handled differently 4389 // since setting native thread priorities is handled differently
4390 // when using this library. All threads created using T2 are bound 4390 // when using this library. All threads created using T2 are bound
4391 // threads. Calling thr_setprio is meaningless in this case. 4391 // threads. Calling thr_setprio is meaningless in this case.
4392 // 4392 //
4393 bool isT2_libthread() { 4393 bool isT2_libthread() {
4394 int i, rslt;
4395 static prheader_t * lwpArray = NULL; 4394 static prheader_t * lwpArray = NULL;
4396 static int lwpSize = 0; 4395 static int lwpSize = 0;
4397 static int lwpFile = -1; 4396 static int lwpFile = -1;
4398 lwpstatus_t * that; 4397 lwpstatus_t * that;
4399 int aslwpcount;
4400 char lwpName [128]; 4398 char lwpName [128];
4401 bool isT2 = false; 4399 bool isT2 = false;
4402 4400
4403 #define ADR(x) ((uintptr_t)(x)) 4401 #define ADR(x) ((uintptr_t)(x))
4404 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) 4402 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1))))
4405 4403
4406 aslwpcount = 0; 4404 lwpFile = open("/proc/self/lstatus", O_RDONLY, 0);
4405 if (lwpFile < 0) {
4406 if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n");
4407 return false;
4408 }
4407 lwpSize = 16*1024; 4409 lwpSize = 16*1024;
4408 lwpArray = ( prheader_t *)NEW_C_HEAP_ARRAY (char, lwpSize);
4409 lwpFile = open ("/proc/self/lstatus", O_RDONLY, 0);
4410 if (lwpArray == NULL) {
4411 if ( ThreadPriorityVerbose ) warning ("Couldn't allocate T2 Check array\n");
4412 return(isT2);
4413 }
4414 if (lwpFile < 0) {
4415 if ( ThreadPriorityVerbose ) warning ("Couldn't open /proc/self/lstatus\n");
4416 return(isT2);
4417 }
4418 for (;;) { 4410 for (;;) {
4419 lseek (lwpFile, 0, SEEK_SET); 4411 lseek (lwpFile, 0, SEEK_SET);
4420 rslt = read (lwpFile, lwpArray, lwpSize); 4412 lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize);
4413 if (read(lwpFile, lwpArray, lwpSize) < 0) {
4414 if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n");
4415 break;
4416 }
4421 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) { 4417 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) {
4418 // We got a good snapshot - now iterate over the list.
4419 int aslwpcount = 0;
4420 for (int i = 0; i < lwpArray->pr_nent; i++ ) {
4421 that = LWPINDEX(lwpArray,i);
4422 if (that->pr_flags & PR_ASLWP) {
4423 aslwpcount++;
4424 }
4425 }
4426 if (aslwpcount == 0) isT2 = true;
4422 break; 4427 break;
4423 } 4428 }
4424 FREE_C_HEAP_ARRAY(char, lwpArray);
4425 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize; 4429 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize;
4426 lwpArray = ( prheader_t *)NEW_C_HEAP_ARRAY (char, lwpSize); 4430 FREE_C_HEAP_ARRAY(char, lwpArray); // retry.
4427 if (lwpArray == NULL) { 4431 }
4428 if ( ThreadPriorityVerbose ) warning ("Couldn't allocate T2 Check array\n");
4429 return(isT2);
4430 }
4431 }
4432
4433 // We got a good snapshot - now iterate over the list.
4434 for (i = 0; i < lwpArray->pr_nent; i++ ) {
4435 that = LWPINDEX(lwpArray,i);
4436 if (that->pr_flags & PR_ASLWP) {
4437 aslwpcount++;
4438 }
4439 }
4440 if ( aslwpcount == 0 ) isT2 = true;
4441 4432
4442 FREE_C_HEAP_ARRAY(char, lwpArray); 4433 FREE_C_HEAP_ARRAY(char, lwpArray);
4443 close (lwpFile); 4434 close (lwpFile);
4444 if ( ThreadPriorityVerbose ) { 4435 if (ThreadPriorityVerbose) {
4445 if ( isT2 ) tty->print_cr("We are running with a T2 libthread\n"); 4436 if (isT2) tty->print_cr("We are running with a T2 libthread\n");
4446 else tty->print_cr("We are not running with a T2 libthread\n"); 4437 else tty->print_cr("We are not running with a T2 libthread\n");
4447 } 4438 }
4448 return (isT2); 4439 return isT2;
4449 } 4440 }
4450 4441
4451 4442
4452 void os::Solaris::libthread_init() { 4443 void os::Solaris::libthread_init() {
4453 address func = (address)dlsym(RTLD_DEFAULT, "_thr_suspend_allmutators"); 4444 address func = (address)dlsym(RTLD_DEFAULT, "_thr_suspend_allmutators");