3543 } /* end GetTime */ 3544 3545 3546 // processor_count_ptr - pre-checked for NULL 3547 jvmtiError 3548 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) { 3549 *processor_count_ptr = os::active_processor_count(); 3550 return JVMTI_ERROR_NONE; 3551 } /* end GetAvailableProcessors */ 3552 3553 // 3554 // System Properties functions 3555 // 3556 3557 // count_ptr - pre-checked for NULL 3558 // property_ptr - pre-checked for NULL 3559 jvmtiError 3560 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) { 3561 jvmtiError err = JVMTI_ERROR_NONE; 3562 3563 *count_ptr = Arguments::PropertyList_count(Arguments::system_properties()); 3564 3565 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr); 3566 if (err != JVMTI_ERROR_NONE) { 3567 return err; 3568 } 3569 int i = 0 ; 3570 for (SystemProperty* p = Arguments::system_properties(); p != NULL && i < *count_ptr; p = p->next(), i++) { 3571 const char *key = p->key(); 3572 char **tmp_value = *property_ptr+i; 3573 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value); 3574 if (err == JVMTI_ERROR_NONE) { 3575 strcpy(*tmp_value, key); 3576 } else { 3577 // clean up previously allocated memory. 3578 for (int j=0; j<i; j++) { 3579 Deallocate((unsigned char*)*property_ptr+j); 3580 } 3581 Deallocate((unsigned char*)property_ptr); 3582 break; 3583 } 3584 } 3585 return err; 3586 } /* end GetSystemProperties */ 3587 3588 3589 // property - pre-checked for NULL 3590 // value_ptr - pre-checked for NULL 3591 jvmtiError 3592 JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) { 3593 jvmtiError err = JVMTI_ERROR_NONE; 3594 const char *value; 3595 3596 if (Arguments::is_internal_module_property(property)) { 3597 return JVMTI_ERROR_NOT_AVAILABLE; 3598 } 3599 value = Arguments::PropertyList_get_value(Arguments::system_properties(), property); 3600 if (value == NULL) { 3601 err = JVMTI_ERROR_NOT_AVAILABLE; 3602 } else { 3603 err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr); 3604 if (err == JVMTI_ERROR_NONE) { 3605 strcpy(*value_ptr, value); 3606 } 3607 } 3608 return err; 3609 } /* end GetSystemProperty */ 3610 3611 3612 // property - pre-checked for NULL 3613 // value - NULL is a valid value, must be checked 3614 jvmtiError 3615 JvmtiEnv::SetSystemProperty(const char* property, const char* value_ptr) { 3616 jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE; 3617 3618 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { 3619 if (strcmp(property, p->key()) == 0) { | 3543 } /* end GetTime */ 3544 3545 3546 // processor_count_ptr - pre-checked for NULL 3547 jvmtiError 3548 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) { 3549 *processor_count_ptr = os::active_processor_count(); 3550 return JVMTI_ERROR_NONE; 3551 } /* end GetAvailableProcessors */ 3552 3553 // 3554 // System Properties functions 3555 // 3556 3557 // count_ptr - pre-checked for NULL 3558 // property_ptr - pre-checked for NULL 3559 jvmtiError 3560 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) { 3561 jvmtiError err = JVMTI_ERROR_NONE; 3562 3563 // Get the number of readable properties. 3564 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties()); 3565 3566 // Allocate memory to hold the exact number of readable properties. 3567 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr); 3568 if (err != JVMTI_ERROR_NONE) { 3569 return err; 3570 } 3571 int readable_count = 0; 3572 // Loop through the system properties until all the readable properties are found. 3573 for (SystemProperty* p = Arguments::system_properties(); p != NULL && readable_count < *count_ptr; p = p->next()) { 3574 if (p->is_readable()) { 3575 const char *key = p->key(); 3576 char **tmp_value = *property_ptr+readable_count++; 3577 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value); 3578 if (err == JVMTI_ERROR_NONE) { 3579 strcpy(*tmp_value, key); 3580 } else { 3581 // clean up previously allocated memory. 3582 for (int j=0; j<readable_count; j++) { 3583 Deallocate((unsigned char*)*property_ptr+j); 3584 } 3585 Deallocate((unsigned char*)property_ptr); 3586 break; 3587 } 3588 } 3589 } 3590 assert(err != JVMTI_ERROR_NONE || readable_count == *count_ptr, "Bad readable property count"); 3591 return err; 3592 } /* end GetSystemProperties */ 3593 3594 3595 // property - pre-checked for NULL 3596 // value_ptr - pre-checked for NULL 3597 jvmtiError 3598 JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) { 3599 jvmtiError err = JVMTI_ERROR_NONE; 3600 const char *value; 3601 3602 // Return JVMTI_ERROR_NOT_AVAILABLE if property is not readable or doesn't exist. 3603 value = Arguments::PropertyList_get_readable_value(Arguments::system_properties(), property); 3604 if (value == NULL) { 3605 err = JVMTI_ERROR_NOT_AVAILABLE; 3606 } else { 3607 err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr); 3608 if (err == JVMTI_ERROR_NONE) { 3609 strcpy(*value_ptr, value); 3610 } 3611 } 3612 return err; 3613 } /* end GetSystemProperty */ 3614 3615 3616 // property - pre-checked for NULL 3617 // value - NULL is a valid value, must be checked 3618 jvmtiError 3619 JvmtiEnv::SetSystemProperty(const char* property, const char* value_ptr) { 3620 jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE; 3621 3622 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { 3623 if (strcmp(property, p->key()) == 0) { |