diff --git a/vm/em/src/DrlEMImpl.cpp b/vm/em/src/DrlEMImpl.cpp
index 461f514..9e353a7 100644
--- a/vm/em/src/DrlEMImpl.cpp
+++ b/vm/em/src/DrlEMImpl.cpp
@@ -195,7 +195,7 @@ #endif
std::string path = origPath;
if (path.find('/') == path.npos && path.find('\\') == path.npos ) {
- char* c_string_tmp_value = get_property(O_A_H_VM_VMDIR, JAVA_PROPERTIES);
+ const char* c_string_tmp_value = get_property(O_A_H_VM_VMDIR, JAVA_PROPERTIES);
std::string dir = c_string_tmp_value == NULL ? "" : c_string_tmp_value;
destroy_property_value(c_string_tmp_value);
if (libPrefix.length() > 0 && !startsWith(path, libPrefix)) {
@@ -328,7 +328,7 @@ static std::string readFile(const std::s
}
std::string DrlEMImpl::readConfiguration() {
- char* c_string_tmp_value = get_property("em.properties", VM_PROPERTIES);
+ const char* c_string_tmp_value = get_property("em.properties", VM_PROPERTIES);
std::string configFileName = c_string_tmp_value == NULL ? "" : c_string_tmp_value;
destroy_property_value(c_string_tmp_value);
if (configFileName.empty()) {
@@ -395,7 +395,7 @@ bool DrlEMImpl::initJIT(const std::strin
std::string DrlEMImpl::getJITLibFromCmdLine(const std::string& jitName) const {
std::string propName = std::string("em.")+jitName+".jitPath";
- char* c_string_tmp_value = get_property(propName.c_str(), VM_PROPERTIES);
+ const char* c_string_tmp_value = get_property(propName.c_str(), VM_PROPERTIES);
std::string jitLib = c_string_tmp_value == NULL ? "" : c_string_tmp_value;
destroy_property_value(c_string_tmp_value);
if (jitLib.empty()) {
diff --git a/vm/gc_cc/src/init.cpp b/vm/gc_cc/src/init.cpp
index eeedf53..a91e6d6 100644
--- a/vm/gc_cc/src/init.cpp
+++ b/vm/gc_cc/src/init.cpp
@@ -71,7 +71,7 @@ void* mem_reserve(size_t size) {
}
void mem_unreserve(void *ptr, size_t size) {
bool UNUSED res = VirtualFree(ptr, 0, MEM_RELEASE);
- int err = GetLastError();
+ int err = GetLastError();
assert(res);
}
@@ -105,7 +105,7 @@ #endif
static size_t get_size_property(const char* name)
{
- char* size_string = get_property(name, VM_PROPERTIES);
+ const char* size_string = get_property(name, VM_PROPERTIES);
size_t size = atol(size_string);
int sizeModifier = tolower(size_string[strlen(size_string) - 1]);
destroy_property_value(size_string);
@@ -174,7 +174,7 @@ #endif
if (is_property_set("gc.lp", VM_PROPERTIES) == 1) {
- char* value = get_property("gc.lp", VM_PROPERTIES);
+ const char* value = get_property("gc.lp", VM_PROPERTIES);
lp_hint = strdup(value);
destroy_property_value(value);
}
diff --git a/vm/gc_gen/src/common/gc_common.cpp b/vm/gc_gen/src/common/gc_common.cpp
index d54336a..2ee312d 100644
--- a/vm/gc_gen/src/common/gc_common.cpp
+++ b/vm/gc_gen/src/common/gc_common.cpp
@@ -56,7 +56,7 @@ extern Boolean IS_MOVE_COMPACT;
static int get_int_property(const char *property_name)
{
assert(property_name);
- char *value = get_property(property_name, VM_PROPERTIES);
+ const char *value = get_property(property_name, VM_PROPERTIES);
int return_value;
if (NULL != value)
{
@@ -73,7 +73,7 @@ static int get_int_property(const char *
static Boolean get_boolean_property(const char *property_name)
{
assert(property_name);
- char *value = get_property(property_name, VM_PROPERTIES);
+ const char *value = get_property(property_name, VM_PROPERTIES);
if (NULL == value){
printf("property value %s is not set\n", property_name);
exit(0);
@@ -104,7 +104,7 @@ static Boolean get_boolean_property(cons
static size_t get_size_property(const char* name)
{
- char* size_string = get_property(name, VM_PROPERTIES);
+ const char* size_string = get_property(name, VM_PROPERTIES);
size_t size = atol(size_string);
int sizeModifier = tolower(size_string[strlen(size_string) - 1]);
destroy_property_value(size_string);
@@ -172,8 +172,8 @@ void gc_parse_options(GC* gc)
/* GC algorithm decision */
/* Step 1: */
- char* minor_algo = NULL;
- char* major_algo = NULL;
+ const char* minor_algo = NULL;
+ const char* major_algo = NULL;
if (is_property_set("gc.minor_algorithm", VM_PROPERTIES) == 1) {
minor_algo = get_property("gc.minor_algorithm", VM_PROPERTIES);
@@ -183,7 +183,9 @@ void gc_parse_options(GC* gc)
major_algo = get_property("gc.major_algorithm", VM_PROPERTIES);
}
- gc_decide_collection_algorithm((GC_Gen*)gc, minor_algo, major_algo);
+ gc_decide_collection_algorithm((GC_Gen*)gc,
+ minor_algo ? strdup(minor_algo) : NULL,
+ major_algo ? strdup(major_algo) : NULL);
gc->generate_barrier = gc_is_gen_mode();
if( minor_algo) destroy_property_value(minor_algo);
@@ -223,7 +225,7 @@ void gc_parse_options(GC* gc)
}
if (is_property_set("gc.verify", VM_PROPERTIES) == 1) {
- char* value = get_property("gc.verify", VM_PROPERTIES);
+ const char* value = get_property("gc.verify", VM_PROPERTIES);
GC_VERIFY = strdup(value);
destroy_property_value(value);
}
@@ -238,7 +240,7 @@ void gc_parse_options(GC* gc)
}
if (is_property_set("gc.use_large_page", VM_PROPERTIES) == 1){
- char* value = get_property("gc.use_large_page", VM_PROPERTIES);
+ const char* value = get_property("gc.use_large_page", VM_PROPERTIES);
large_page_hint = strdup(value);
destroy_property_value(value);
}
diff --git a/vm/gc_gen/src/gen/gen.cpp b/vm/gc_gen/src/gen/gen.cpp
index 1bb42fc..8e61862 100644
--- a/vm/gc_gen/src/gen/gen.cpp
+++ b/vm/gc_gen/src/gen/gen.cpp
@@ -321,6 +321,9 @@ void gc_decide_collection_algorithm(GC_G
}
}
+
+ free(minor_algo);
+ free(major_algo);
return;
@@ -423,8 +426,8 @@ void gc_gen_iterate_heap(GC_Gen *gc)
bool cont = true;
while (mutator) {
Block_Header* block = (Block_Header*)mutator->alloc_block;
- if(block != NULL) block->free = mutator->free;
- mutator = mutator->next;
+ if(block != NULL) block->free = mutator->free;
+ mutator = mutator->next;
}
Mspace* mspace = gc->mos;
@@ -446,14 +449,14 @@ void gc_gen_iterate_heap(GC_Gen *gc)
curr_block = (Block_Header*)fspace->blocks;
space_end = (Block_Header*)&fspace->blocks[fspace->free_block_idx - fspace->first_block_idx];
while(curr_block < space_end) {
- POINTER_SIZE_INT p_obj = (POINTER_SIZE_INT)curr_block->base;
+ POINTER_SIZE_INT p_obj = (POINTER_SIZE_INT)curr_block->base;
POINTER_SIZE_INT block_end = (POINTER_SIZE_INT)curr_block->free;
while(p_obj < block_end){
cont = vm_iterate_object((Managed_Object_Handle)p_obj);
if (!cont) return;
p_obj = p_obj + vm_object_size((Partial_Reveal_Object *)p_obj);
}
- curr_block = curr_block->next;
+ curr_block = curr_block->next;
if(curr_block == NULL) break;
}
diff --git a/vm/include/open/vm.h b/vm/include/open/vm.h
index f1efa1b..dfaf084 100644
--- a/vm/include/open/vm.h
+++ b/vm/include/open/vm.h
@@ -1015,12 +1015,12 @@ VMEXPORT void set_property(const char* k
* @return The value of the property from table_number property table if it
* has been set by set_property function. Otherwise NULL.
*/
-VMEXPORT char* get_property(const char* key, PropertyTable table_number);
+VMEXPORT const char* get_property(const char* key, PropertyTable table_number);
/**
* Safety frees memory of value returned by get_property function.
*/
-VMEXPORT void destroy_property_value(char* value);
+VMEXPORT void destroy_property_value(const char* value);
/**
* Checks if the property is set.
diff --git a/vm/jitrino/src/main/PMF.cpp b/vm/jitrino/src/main/PMF.cpp
index 531a3a3..24c395f 100644
--- a/vm/jitrino/src/main/PMF.cpp
+++ b/vm/jitrino/src/main/PMF.cpp
@@ -1363,7 +1363,7 @@ void PMF::processVMProperties ()
while (keys[i] != NULL) {
if (strncmp("jit.", keys[i], 4) == 0)
{
- char* value = get_property(keys[i], VM_PROPERTIES);
+ const char* value = get_property(keys[i], VM_PROPERTIES);
processCmd(keys[i] + 4, value);
destroy_property_value(value);
}
diff --git a/vm/vmcore/include/properties.h b/vm/vmcore/include/properties.h
index 6570551..075ec20 100644
--- a/vm/vmcore/include/properties.h
+++ b/vm/vmcore/include/properties.h
@@ -21,6 +21,7 @@ #define _VM_PROPERTIES_H
#include
#include
#include
+#include
class Properties
{
@@ -32,8 +33,8 @@ public:
void set(const char * key, const char * value);
/** set property only if it's not set yet */
void set_new(const char * key, const char * value);
- char* get(const char * key);
- void destroy(char* value);
+ const char* get(const char * key);
+ void destroy(const char* value);
bool is_set(const char * key);
void unset(const char * key);
char** get_keys();
diff --git a/vm/vmcore/src/class_support/C_Interface.cpp b/vm/vmcore/src/class_support/C_Interface.cpp
index fdfdfb3..4c2f4b3 100644
--- a/vm/vmcore/src/class_support/C_Interface.cpp
+++ b/vm/vmcore/src/class_support/C_Interface.cpp
@@ -2168,7 +2168,7 @@ int class_get_referent_offset(Class_Hand
void* class_alloc_via_classloader(Class_Handle ch, int32 size)
{
assert(ch);
- assert(size >= 0);
+ assert(size >= 0);
Class *clss = (Class *)ch;
assert (clss->get_class_loader());
return clss->get_class_loader()->Alloc(size);
@@ -2625,7 +2625,7 @@ void set_property(const char* key, const
switch(table_number) {
case JAVA_PROPERTIES:
VM_Global_State::loader_env->JavaProperties()->set(key, value);
- break;
+ break;
case VM_PROPERTIES:
VM_Global_State::loader_env->VmProperties()->set(key, value);
break;
@@ -2634,10 +2634,10 @@ void set_property(const char* key, const
}
}
-char* get_property(const char* key, PropertyTable table_number)
+const char* get_property(const char* key, PropertyTable table_number)
{
assert(key);
- char* value;
+ const char* value;
switch(table_number) {
case JAVA_PROPERTIES:
value = VM_Global_State::loader_env->JavaProperties()->get(key);
@@ -2652,7 +2652,7 @@ char* get_property(const char* key, Prop
return value;
}
-void destroy_property_value(char* value)
+void destroy_property_value(const char* value)
{
if (value)
{
@@ -2741,7 +2741,7 @@ void destroy_properties_keys(char** keys
int get_int_property(const char *property_name, int default_value, PropertyTable table_number)
{
assert(property_name);
- char *value = get_property(property_name, table_number);
+ const char *value = get_property(property_name, table_number);
int return_value = default_value;
if (NULL != value)
{
@@ -2754,7 +2754,7 @@ int get_int_property(const char *propert
int64 get_numerical_property(const char *property_name, int64 default_value, PropertyTable table_number)
{
assert(property_name);
- char *value = get_property(property_name, table_number);
+ const char *value = get_property(property_name, table_number);
int64 return_value = default_value;
if (NULL != value)
{
@@ -2780,7 +2780,7 @@ int64 get_numerical_property(const char
Boolean get_boolean_property(const char *property_name, Boolean default_value, PropertyTable table_number)
{
assert(property_name);
- char *value = get_property(property_name, table_number);
+ const char *value = get_property(property_name, table_number);
if (NULL == value)
{
return default_value;
diff --git a/vm/vmcore/src/class_support/classloader.cpp b/vm/vmcore/src/class_support/classloader.cpp
index 8cf571f..399ede7 100644
--- a/vm/vmcore/src/class_support/classloader.cpp
+++ b/vm/vmcore/src/class_support/classloader.cpp
@@ -1104,7 +1104,6 @@ inline void BootstrapClassLoader::SetCla
size_t len = strlen(jar_classpath) + 1;
char* classpath = (char*)STD_ALLOCA(len);
memcpy(classpath, jar_classpath, len);
- STD_FREE((void*)jar_classpath); //FIXME inconsistent MM
#ifdef PLATFORM_NT
//on windows, we change the path to lower case
strlwr(classpath);
@@ -1238,7 +1237,8 @@ bool BootstrapClassLoader::Initialize(Ma
ClassLoader::Initialize();
// get list of natives libraries
- char *lib_list = m_env->VmProperties()->get("vm.other_natives_dlls");
+ const char* lib_list_const = m_env->VmProperties()->get("vm.other_natives_dlls");
+ char *lib_list = lib_list_const ? strdup(lib_list_const) : NULL;
// separate natives libraries
const char separator[2] = {PORT_PATH_SEPARATOR, 0};
@@ -1252,7 +1252,10 @@ bool BootstrapClassLoader::Initialize(Ma
// find next library
lib_name = strtok( NULL, separator );
}
- m_env->VmProperties()->destroy(lib_list);
+ m_env->VmProperties()->destroy(lib_list_const);
+
+ if (lib_list)
+ free(lib_list);
/*
* at this point, LUNI is loaded, so we can use the boot classpath
@@ -1270,7 +1273,7 @@ bool BootstrapClassLoader::Initialize(Ma
*/
/* strdup so that it's freeable w/o extra logic */
- char *temp = m_env->VmProperties()->get(XBOOTCLASSPATH);
+ const char *temp = m_env->VmProperties()->get(XBOOTCLASSPATH);
char *bcp_value = (temp ? strdup(temp) : NULL);
m_env->VmProperties()->destroy(temp);
@@ -1278,7 +1281,7 @@ bool BootstrapClassLoader::Initialize(Ma
/* not overridden, so lets build, adding the kernel to what luni made for us */
- char *kernel_dir_path = m_env->JavaProperties()->get(O_A_H_VM_VMDIR);
+ const char *kernel_dir_path = m_env->JavaProperties()->get(O_A_H_VM_VMDIR);
char* comp_path = bootstrap_components_classpath(m_env);
char *kernel_path = (char *) malloc(strlen(kernel_dir_path)
@@ -1296,7 +1299,7 @@ bool BootstrapClassLoader::Initialize(Ma
STD_FREE(comp_path);
}
- char *luni_path = m_env->JavaProperties()->get(O_A_H_BOOT_CLASS_PATH);
+ const char *luni_path = m_env->JavaProperties()->get(O_A_H_BOOT_CLASS_PATH);
char *vmboot = (char *) malloc(strlen(luni_path == NULL ? "" : luni_path)
+ strlen(kernel_path) + strlen(PORT_PATH_SEPARATOR_STR) + 1);
@@ -1314,8 +1317,8 @@ bool BootstrapClassLoader::Initialize(Ma
* now if there a pre or post bootclasspath, add those
*/
- char *prepend = m_env->VmProperties()->get(XBOOTCLASSPATH_P);
- char *append = m_env->VmProperties()->get(XBOOTCLASSPATH_A);
+ const char *prepend = m_env->VmProperties()->get(XBOOTCLASSPATH_P);
+ const char *append = m_env->VmProperties()->get(XBOOTCLASSPATH_A);
if (prepend || append) {
@@ -1363,9 +1366,11 @@ bool BootstrapClassLoader::Initialize(Ma
// check if vm.bootclasspath.appendclasspath property is set to true
if( TRUE == get_boolean_property("vm.bootclasspath.appendclasspath", FALSE, VM_PROPERTIES) ) {
// append classpath to bootclasspath
- char * cp = m_env->JavaProperties()->get("java.class.path");
- SetClasspathFromString(cp, tmp_pool);
+ const char * cp = m_env->JavaProperties()->get("java.class.path");
+ char * cp_copy = (cp ? strdup(cp) : NULL);
+ SetClasspathFromString(cp_copy, tmp_pool);
m_env->JavaProperties()->destroy(cp);
+ free(cp_copy);
}
// get a classpath from archive files manifest and
diff --git a/vm/vmcore/src/init/parse_arguments.cpp b/vm/vmcore/src/init/parse_arguments.cpp
index a6d28e3..78ad449 100644
--- a/vm/vmcore/src/init/parse_arguments.cpp
+++ b/vm/vmcore/src/init/parse_arguments.cpp
@@ -325,7 +325,7 @@ #endif //_DEBUG
* Note that we accumulate if multiple, appending each time
*/
- char *bcp_old = p_env->VmProperties()->get(XBOOTCLASSPATH_A);
+ const char *bcp_old = p_env->VmProperties()->get(XBOOTCLASSPATH_A);
const char *value = option + strlen(XBOOTCLASSPATH_A);
char *bcp_new = NULL;
@@ -351,7 +351,7 @@ #endif //_DEBUG
* Note that we accumulate if multiple, prepending each time
*/
- char *bcp_old = p_env->VmProperties()->get(XBOOTCLASSPATH_P);
+ const char *bcp_old = p_env->VmProperties()->get(XBOOTCLASSPATH_P);
const char *value = option + strlen(XBOOTCLASSPATH_P);
char *bcp_new = NULL;
diff --git a/vm/vmcore/src/init/properties.cpp b/vm/vmcore/src/init/properties.cpp
index 7e0aac3..de1458c 100644
--- a/vm/vmcore/src/init/properties.cpp
+++ b/vm/vmcore/src/init/properties.cpp
@@ -17,20 +17,10 @@
#define LOG_DOMAIN "init.properties"
#include "cxxlog.h"
-#include "properties.h"
+#include "environment.h"
-class PropValue
-{
-public:
- char* value;
+#include "properties.h"
- PropValue(const char* v) {
- value = (v == NULL ? NULL : (char*)strdup(v));
- }
- ~PropValue() {
- STD_FREE(value);
- }
-};
Properties::Properties()
{
@@ -44,92 +34,105 @@ Properties::Properties()
}
}
-void Properties::set(const char * key, const char * value)
+void Properties::set(const char * key, const char * value)
{
TRACE("set property " << key << " = " << value);
- if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array)) {
+ if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array))
LDIE(11, "Cannot lock properties table");
+
+ String* old_val = (String*)apr_hash_get(hashtables_array, (const void*)key, APR_HASH_KEY_STRING);
+ String* new_val = VM_Global_State::loader_env->string_pool.lookup(value);
+ assert(new_val);
+
+ if (old_val != new_val)
+ {
+ apr_hash_set(hashtables_array, (const void*)strdup(key),
+ APR_HASH_KEY_STRING, (const void*)new_val);
}
- PropValue* val = (PropValue*) apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING);
- apr_hash_set(hashtables_array, (const void*) strdup(key), APR_HASH_KEY_STRING, (const void*) new PropValue(value));
- if (val != NULL) {
- delete(val);
- }
- if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {
+
+ if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array))
LDIE(12, "Cannot unlock properties table");
- }
}
void Properties::set_new(const char * key, const char * value)
{
TRACE("try to set property " << key << " = " << value);
- if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array)) {
+ if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array))
LDIE(11, "Cannot lock properties table");
- }
- PropValue* val = (PropValue*) apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING);
- if (NULL == val) {
- apr_hash_set(hashtables_array, (const void*) strdup(key), APR_HASH_KEY_STRING, (const void*) new PropValue(value));
+
+ String* old_val = (String*)apr_hash_get(hashtables_array, (const void*)key, APR_HASH_KEY_STRING);
+ String* new_val = VM_Global_State::loader_env->string_pool.lookup(value);
+
+ if (NULL == old_val)
+ {
+ apr_hash_set(hashtables_array, (const void*)strdup(key),
+ APR_HASH_KEY_STRING, (const void*)new_val);
TRACE("defined property " << key);
- } else {
- TRACE("property is already defined: " << key);
}
+ else
+ TRACE("property is already defined: " << key);
- if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {
+ if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array))
LDIE(12, "Cannot unlock properties table");
- }
}
-char* Properties::get(const char * key) {
+const char* Properties::get(const char * key) {
char* return_value= NULL;
- if (APR_SUCCESS != apr_thread_rwlock_rdlock(rwlock_array)) {
+
+ if (APR_SUCCESS != apr_thread_rwlock_rdlock(rwlock_array))
LDIE(11, "Cannot lock properties table");
- }
- PropValue* val = (PropValue*) apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING);
- if (val != NULL) {
- return_value = strdup(val->value);
- }
- if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {
+
+ String* val = (String*)apr_hash_get(hashtables_array, (const void*)key, APR_HASH_KEY_STRING);
+
+ if (val != NULL)
+ return_value = val->bytes;
+
+ if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array))
LDIE(12, "Cannot unlock properties table");
- }
+
return return_value;
}
-void Properties::destroy(char* value) {
- STD_FREE((void*)value);
+void Properties::destroy(const char* value) {
+// STD_FREE((void*)value);
}
bool Properties::is_set(const char * key) {
- if (apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING) == NULL) {
- return FALSE;
- } else {
- return TRUE;
- }
+ return (apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING) != NULL);
}
void Properties::unset(const char * key) {
apr_hash_index_t* hi;
const void* deleted_key;
- if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array)) {
+ size_t key_len = strlen(key);
+
+ if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array))
LDIE(11, "Cannot lock properties table");
- }
- PropValue* val = (PropValue*) apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING);
- if (val != NULL) {
- for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi)) {
+
+ String* val = (String*)apr_hash_get(hashtables_array, (const void*)key, APR_HASH_KEY_STRING);
+
+ if (val != NULL){
+ for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi))
+ {
apr_hash_this(hi, &deleted_key, NULL, NULL);
- if (!(strncmp(key, (const char*)deleted_key, strlen(key)) &&
- strncmp((const char*)deleted_key, key, strlen((const char*)deleted_key)))) {
+
+ size_t del_len = strlen((const char*)deleted_key);
+
+ if (del_len != key_len)
+ continue;
+
+ if (strcmp(key, (const char*)deleted_key) == 0)
break;
- }
}
+
apr_hash_set(hashtables_array, (const void*)key, APR_HASH_KEY_STRING, NULL);
STD_FREE((void*)deleted_key);
- delete(val);
}
- if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {
+
+ if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array))
LDIE(12, "Cannot unlock properties table");
- }
}
char** Properties::get_keys() {
@@ -137,22 +140,27 @@ char** Properties::get_keys() {
int properties_count = 0;
const void* key;
- if (APR_SUCCESS != apr_thread_rwlock_rdlock(rwlock_array)) {
+ if (APR_SUCCESS != apr_thread_rwlock_rdlock(rwlock_array))
LDIE(11, "Cannot lock properties table");
- }
- for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi)) {
+
+ for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi))
properties_count++;
- }
+
char** return_value = (char**) STD_MALLOC(sizeof(char*) * (properties_count + 1));
+ assert(return_value);
+
properties_count = 0;
- for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi)) {
- apr_hash_this(hi, &key, NULL, NULL);
- return_value[properties_count++] = (char*)strdup((char*)key);
+ for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi))
+ {
+ apr_hash_this(hi, &key, NULL, NULL);
+ return_value[properties_count++] = (char*)strdup((char*)key);
}
+
return_value[properties_count] = NULL;
- if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {
+
+ if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array))
LDIE(12, "Cannot unlock properties table");
- }
+
return return_value;
}
@@ -161,26 +169,34 @@ char** Properties::get_keys_staring_with
int properties_count = 0;
const void* key;
- if (APR_SUCCESS != apr_thread_rwlock_rdlock(rwlock_array)) {
+ if (APR_SUCCESS != apr_thread_rwlock_rdlock(rwlock_array))
LDIE(11, "Cannot lock properties table");
- }
- for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi)) {
+
+ for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi))
+ {
apr_hash_this(hi, &key, NULL, NULL);
+
if (!strncmp(prefix, (char*)key, strlen(prefix)))
properties_count++;
}
+
char** return_value = (char**) STD_MALLOC(sizeof(char*) * (properties_count + 1));
+ assert(return_value);
+
properties_count = 0;
- for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi)) {
+ for (hi = apr_hash_first(local_ht_pool, hashtables_array); hi; hi = apr_hash_next(hi))
+ {
apr_hash_this(hi, &key, NULL, NULL);
- if (!strncmp(prefix, (char*)key, strlen(prefix))) {
+
+ if (!strncmp(prefix, (char*)key, strlen(prefix)))
return_value[properties_count++] = (char*)strdup((char*)key);
- }
}
+
return_value[properties_count] = NULL;
- if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {
+
+ if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array))
LDIE(12, "Cannot unlock properties table");
- }
+
return return_value;
}
diff --git a/vm/vmcore/src/init/vm_init.cpp b/vm/vmcore/src/init/vm_init.cpp
index ad8d935..6d82478 100644
--- a/vm/vmcore/src/init/vm_init.cpp
+++ b/vm/vmcore/src/init/vm_init.cpp
@@ -121,10 +121,14 @@ static jint process_properties_dlls(Glob
vm_env->VmProperties()->set("vm.em_dll", PORT_DSO_NAME("em"));
}
- char* dll = vm_env->VmProperties()->get("vm.em_dll");
+ const char* temp = vm_env->VmProperties()->get("vm.em_dll");
+ char* dll = temp ? strdup(temp) : NULL;
TRACE("analyzing em dll " << dll);
status = CmLoadComponent(dll, "EmInitialize");
- vm_env->VmProperties()->destroy(dll);
+ vm_env->VmProperties()->destroy(temp);
+ if (dll)
+ free(dll);
+
if (status != JNI_OK) {
LWARN(13, "Cannot load EM component from {0}" << dll);
return status;
@@ -145,9 +149,10 @@ static jint process_properties_dlls(Glob
const char delimiters[] = {PORT_PATH_SEPARATOR, 0};
- char* dlls = vm_env->VmProperties()->get("vm.dlls");
- if (!dlls) return JNI_OK;
+ temp = vm_env->VmProperties()->get("vm.dlls");
+ if (!temp) return JNI_OK;
+ char* dlls = strdup(temp);
char* tok = strtok((char *)dlls, delimiters);
while (tok) {
TRACE("analyzing dll " << tok);
@@ -171,7 +176,8 @@ next_dll:
tok = strtok(NULL, delimiters);
}
- vm_env->VmProperties()->destroy(dlls);
+ vm_env->VmProperties()->destroy(temp);
+ free(dlls);
return status;
}
diff --git a/vm/vmcore/src/init/vm_properties.cpp b/vm/vmcore/src/init/vm_properties.cpp
index c6763be..bc58c01 100644
--- a/vm/vmcore/src/init/vm_properties.cpp
+++ b/vm/vmcore/src/init/vm_properties.cpp
@@ -182,7 +182,7 @@ static void init_java_properties(Propert
properties.set(O_A_H_VM_VMDIR, vm_dir);
}
- char* vm_dir = properties.get(O_A_H_VM_VMDIR);
+ const char* vm_dir = properties.get(O_A_H_VM_VMDIR);
char* lib_path = apr_pstrcat(prop_pool, launcher_dir,
PORT_PATH_SEPARATOR_STR, vm_dir, NULL);
diff --git a/vm/vmcore/src/jvmti/jvmti.cpp b/vm/vmcore/src/jvmti/jvmti.cpp
index ca96a09..b2ad66f 100644
--- a/vm/vmcore/src/jvmti/jvmti.cpp
+++ b/vm/vmcore/src/jvmti/jvmti.cpp
@@ -491,7 +491,7 @@ static void generate_platform_lib_name(a
const char *lib_name,
char **p_path1, char **p_path2)
{
- char *vm_libs = vm->vm_env->JavaProperties()->get("vm.boot.library.path");
+ const char *vm_libs = vm->vm_env->JavaProperties()->get("vm.boot.library.path");
assert(vm_libs);
char *path1 = apr_pstrdup(pool, vm_libs);
char *path2 = port_dso_name_decorate(lib_name, pool);
diff --git a/vm/vmcore/src/jvmti/jvmti_property.cpp b/vm/vmcore/src/jvmti/jvmti_property.cpp
index 1fcbec4..cbdcbb5 100644
--- a/vm/vmcore/src/jvmti/jvmti_property.cpp
+++ b/vm/vmcore/src/jvmti/jvmti_property.cpp
@@ -78,7 +78,7 @@ jvmtiAddToBootstrapClassLoaderSearch(jvm
const char* bcp_property = XBOOTCLASSPATH_A;
// get bootclasspath property
- char *bcp_prop = get_property(bcp_property, VM_PROPERTIES);
+ const char *bcp_prop = get_property(bcp_property, VM_PROPERTIES);
size_t len_bcp = 0;
@@ -201,7 +201,7 @@ jvmtiGetSystemProperty(jvmtiEnv* env,
if (NULL == property || NULL == value_ptr)
return JVMTI_ERROR_NULL_POINTER;
- char *value = get_property(property, JAVA_PROPERTIES);
+ const char *value = get_property(property, JAVA_PROPERTIES);
if (NULL == value)
return JVMTI_ERROR_NOT_AVAILABLE;
diff --git a/vm/vmcore/src/kernel_classes/native/java_lang_VMExecutionEngine.cpp b/vm/vmcore/src/kernel_classes/native/java_lang_VMExecutionEngine.cpp
index b47048e..9d369fd 100644
--- a/vm/vmcore/src/kernel_classes/native/java_lang_VMExecutionEngine.cpp
+++ b/vm/vmcore/src/kernel_classes/native/java_lang_VMExecutionEngine.cpp
@@ -154,7 +154,7 @@ JNIEXPORT jobject JNICALL Java_java_lang
Properties *pp = VM_Global_State::loader_env->JavaProperties();
char** keys = pp->get_keys();
for (int i = 0; keys[i] !=NULL; ++i) {
- char* value = pp->get(keys[i]);
+ const char* value = pp->get(keys[i]);
bool added = PropPut(jenv, jprops, keys[i], value);
pp->destroy(value);
if (!added) {
diff --git a/vm/vmi/src/vmi.cpp b/vm/vmi/src/vmi.cpp
index 7d0c9f2..9dc5b85 100644
--- a/vm/vmi/src/vmi.cpp
+++ b/vm/vmi/src/vmi.cpp
@@ -146,7 +146,7 @@ JavaVMInitArgs* JNICALL GetInitArgs(VMIn
vmiError JNICALL
GetSystemProperty(VMInterface *vmi, char *key, char **valuePtr)
{
- char* value = get_property(key, JAVA_PROPERTIES);
+ const char* value = get_property(key, JAVA_PROPERTIES);
*valuePtr = value ? strdup(value) : NULL;
destroy_property_value(value);
return VMI_ERROR_NONE;
@@ -183,7 +183,7 @@ vmiError JNICALL IterateSystemProperties
int count = 0;
while(keys[count] != NULL) {
- char* value = get_property(keys[count], JAVA_PROPERTIES);
+ const char* value = get_property(keys[count], JAVA_PROPERTIES);
/*
* FIXME: possible inconsistency between iterator and
* properties count.