Skip to content

Commit

Permalink
Mem allocs
Browse files Browse the repository at this point in the history
Signed-off-by: tajila <atobia@ca.ibm.com>
  • Loading branch information
tajila committed Sep 18, 2024
1 parent 48be99a commit f8fad9f
Show file tree
Hide file tree
Showing 31 changed files with 110 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
// We have no exact command or the arguments are truncated.
// In this case we save the command line from /proc/<pid>/cmdline.
args = (char*)malloc(pageSize + 1);
printf(" !j9x 0x%p,0x%zX %s\n", args, (size_t)pageSize + 1, "ProcesshandleImpl_linux.c:214");
if (args != NULL) {
memcpy(args, cmdline, cmdlen + 1);
for (i = 0; i < cmdlen; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/macosx/native/libnet/DefaultProxySelector.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ Java_sun_net_spi_DefaultProxySelector_getSystemProxies(JNIEnv *env,

/* Construct the uri, cproto + "://" + chost */
uri = malloc(protoLen + hostLen + 4);
printf(" !j9x 0x%p,0x%zX %s\n", uri,(size_t) protoLen + hostLen + 4, "DEfaultProxySelector.c:196");

if (uri != NULL) {
memcpy(uri, cproto, protoLen);
memcpy(uri + protoLen, "://", 3);
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/native/libjava/Class.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ Java_java_lang_Class_forName0(JNIEnv *env, jclass this, jstring classname,
unicode_len = (*env)->GetStringLength(env, classname);
if (len >= (jsize)sizeof(buf)) {
clname = malloc(len + 1);
printf(" !j9x 0x%p,0x%zX %s\n", clname,(size_t) len + 1, "Class.c:122");


if (clname == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/java.base/share/native/libjava/NativeLibraries.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ static void *findJniFunction(JNIEnv *env, void *handle,
goto done;
}
jniFunctionName = malloc(len);
printf(" !j9x 0x%p,0x%zX %s\n", jniFunctionName,(size_t) len, "NativeLibraries.c:99");

if (jniFunctionName == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
goto done;
Expand Down Expand Up @@ -293,6 +295,8 @@ Java_jdk_internal_loader_NativeLibraries_findBuiltinLib
return NULL;
}
libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
printf(" !j9x 0x%p,0x%zX %s\n", libName, (size_t)len + 1, "NativeLibraries.c:298");

if (libName == NULL) {
JNU_ReleaseStringPlatformChars(env, name, cname);
JNU_ThrowOutOfMemoryError(env, NULL);
Expand Down
4 changes: 4 additions & 0 deletions src/java.base/share/native/libjava/io_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
return 0;
} else if (len > BUF_SIZE) {
buf = malloc(len);
printf(" !j9x 0x%p,0x%zX %s\n", buf,(size_t) len + 1, "io_util.c:96");

if (buf == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return 0;
Expand Down Expand Up @@ -165,6 +167,8 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
return;
} else if (len > BUF_SIZE) {
buf = malloc(len);
printf(" !j9x 0x%p,0x%zX %s\n", buf, (size_t)len, "io_util.c:170");

if (buf == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
Expand Down
10 changes: 9 additions & 1 deletion src/java.base/share/native/libjava/jni_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@
* negative, or the size is INT_MAX as the macro adds 1
* that overflows into negative value.
*/

void* mallocWrap(size_t size) {
void * mem = malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", mem, (size_t)size, "jni_util.c:46");

return mem;
}

#define MALLOC_MIN4(len) ((unsigned)(len) >= INT_MAX ? \
NULL : \
((char *)malloc((len) + 1 < 4 ? 4 : (len) + 1)))
((char *)mallocWrap((len) + 1 < 4 ? 4 : (len) + 1)))

/**
* Throw a Java exception by name. Similar to SignalError.
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/native/libjli/jli_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ JNIEXPORT void * JNICALL
JLI_MemAlloc(size_t size)
{
void *p = malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", p,(size_t) size, "jli_util.c:40");


if (p == 0) {
perror("malloc");
exit(1);
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/launcher/jexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ int main(int argc, const char * argv[]) {
errorExit(errno, BAD_ARG_MSG);
}
nargv = (const char **) malloc(alen);
printf(" !j9x 0x%p,0x%zX %s\n", nargv, (size_t)alen, "jexec.c:179");

if (nargv == NULL) {
errorExit(errno, MEM_FAILED_MSG);
}
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ void unix_getUserInfo(JNIEnv* env, jobject jinfo, uid_t uid) {

/* allocate buffer for password record */
pwbuf = (char*)malloc(getpw_buf_size);
printf(" !j9x 0x%p,0x%zX %s\n", pwbuf, (size_t)getpw_buf_size, "ProcessHandleImpl_unix.c:468");

if (pwbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "Unable to open getpwent");
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libjava/ProcessImpl_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ static void*
xmalloc(JNIEnv *env, size_t size)
{
void *p = malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", p,(size_t) size, "ProcessHandleImpl_md.c:218");

if (p == NULL)
JNU_ThrowOutOfMemoryError(env, NULL);
return p;
Expand Down
6 changes: 6 additions & 0 deletions src/java.base/unix/native/libjava/TimeZone_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ getPathName(const char *dir, const char *name) {
char *path;

path = (char *) malloc(strlen(dir) + strlen(name) + 2);
printf(" !j9x 0x%p,0x%zX %s\n", path,(size_t) strlen(dir) + strlen(name) + 2, "Timezon_md.c:106");

if (path == NULL) {
return NULL;
}
Expand Down Expand Up @@ -206,6 +208,8 @@ isFileIdentical(char *buf, size_t size, char *pathname)
possibleMatch = findZoneinfoFile(buf, size, pathname);
} else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
dbuf = (char *) malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", dbuf,(size_t) size, "Timezon_md.c:211");

if (dbuf == NULL) {
return NULL;
}
Expand Down Expand Up @@ -321,6 +325,8 @@ getPlatformTimeZoneID()
}
size = (size_t) statbuf.st_size;
buf = (char *) malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", buf,(size_t) size, "Timezon_md.c:328");

if (buf == NULL) {
(void) close(fd);
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libjava/io_util_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jstring newStringPlatform(JNIEnv *env, const char* str)
int clen = CFStringGetLength(csref);
int ulen = (clen + 1) * 2; // utf16 + zero padding
char* chars = malloc(ulen);
printf(" !j9x 0x%p,0x%zX %s\n", chars,(size_t) ulen, "io_util_md.c:59");

if (chars == NULL) {
CFRelease(csref);
JNU_ThrowOutOfMemoryError(env, "native heap");
Expand Down
12 changes: 12 additions & 0 deletions src/java.base/unix/native/libjava/java_props_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
}

temp = malloc(strlen(lc) + 1);
printf(" !j9x 0x%p,0x%zX %s\n", temp, (size_t)strlen(lc) + 1, "java_props_md.c:115");

if (temp == NULL) {
#ifdef MACOSX
free(lc); // malloced memory
Expand Down Expand Up @@ -143,6 +145,7 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
}

temp = malloc(strlen(lc) + 1);
printf(" !j9x 0x%p,0x%zX %s\n", temp, (size_t)strlen(lc) + 1, "java_props_md.c:148");
if (temp == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return 0;
Expand Down Expand Up @@ -175,6 +178,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
*/

encoding_variant = malloc(strlen(temp)+1);
printf(" !j9x 0x%p,0x%zX %s\n", encoding_variant, (size_t)strlen(temp)+1, "java_props_md.c:181");

if (encoding_variant == NULL) {
free(temp);
JNU_ThrowOutOfMemoryError(env, NULL);
Expand Down Expand Up @@ -238,6 +243,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
*std_language = "en";
if (language != NULL && mapLookup(language_names, language, std_language) == 0) {
*std_language = malloc(strlen(language)+1);
printf(" !j9x 0x%p,0x%zX %s\n", *std_language, (size_t)strlen(language)+1, "java_props_md.c:246");

strcpy(*std_language, language);
}
}
Expand All @@ -246,6 +253,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
if (std_country != NULL && country != NULL) {
if (mapLookup(country_names, country, std_country) == 0) {
*std_country = malloc(strlen(country)+1);
printf(" !j9x 0x%p,0x%zX %s\n", *std_country,(size_t) strlen(country)+1, "java_props_md.c:256");

strcpy(*std_country, country);
}
}
Expand Down Expand Up @@ -405,6 +414,9 @@ GetJavaProperties(JNIEnv *env)
{
char *os_version = malloc(strlen(name.version) +
strlen(name.release) + 2);

printf(" !j9x 0x%p,0x%zX %s\n", os_version,(size_t) strlen(name.version) + strlen(name.release) + 2, "java_props_md.c:418");

if (os_version != NULL) {
strcpy(os_version, name.version);
strcat(os_version, ".");
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/DefaultProxySelector.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ static jobjectArray getProxyByGProxyResolver(JNIEnv *env, const char *cproto,
protoLen = strlen(cproto);
hostLen = strlen(chost);
uri = malloc(protoLen + hostLen + 4);
printf(" !j9x 0x%p,0x%zX %s\n", uri,(size_t) protoLen + hostLen + 4, "DEfaultProxySelector.c:349");

if (!uri) {
/* Out of memory */
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/Inet4AddressImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
if (!skip) {
struct addrinfo *next
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
printf(" !j9x 0x%p,0x%zX %s\n", next,(size_t) sizeof(struct addrinfo), "Inet4address.c:143");

if (!next) {
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/Inet6AddressImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
if (!skip) {
struct addrinfo *next
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
printf(" !j9x 0x%p,0x%zX %s\n", next,(size_t) sizeof(struct addrinfo), "Inet6address.c:143");

if (!next) {
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#define CHECKED_MALLOC3(_pointer, _type, _size) \
do { \
_pointer = (_type)malloc(_size); \
printf(" !j9x 0x%p,0x%zX %s\n", _pointer,(size_t) _size, "NetworkInterface.c:63"); \
if (_pointer == NULL) { \
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); \
return ifs; /* return untouched list */ \
Expand Down Expand Up @@ -1601,6 +1602,7 @@ static int getMacAddress
}

nddp = (struct kinfo_ndd *)malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", nddp,(size_t) size, "NetworkInterface.c:1605");

if (!nddp) {
JNU_ThrowOutOfMemoryError(env,
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ Java_java_net_PlainDatagramSocketImpl_send0(JNIEnv *env, jobject this,
packetBufferLen = MAX_PACKET_LEN;
}
fullPacket = (char *)malloc(packetBufferLen);
printf(" !j9x 0x%p,0x%zX %s\n", fullPacket,(size_t) packetBufferLen, "PlainDatagramSocket.c:404");

if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "Send buffer native heap allocation failed");
Expand Down Expand Up @@ -750,6 +751,8 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this,
packetBufferLen = MAX_PACKET_LEN;
}
fullPacket = (char *)malloc(packetBufferLen);
printf(" !j9x 0x%p,0x%zX %s\n", fullPacket,(size_t) packetBufferLen, "PlainDatagramSocket.c:755");


if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "Receive buffer native heap allocation failed");
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/SocketInputStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
len = MAX_HEAP_BUFFER_LEN;
}
bufP = (char *)malloc((size_t)len);
printf(" !j9x 0x%p,0x%zX %s\n", bufP,(size_t) len, "SocketInputStream.c:119");

if (bufP == NULL) {
bufP = BUF;
len = MAX_BUFFER_LEN;
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/SocketOutputStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Java_java_net_SocketOutputStream_socketWrite0(JNIEnv *env, jobject this,
} else {
buflen = min(MAX_HEAP_BUFFER_LEN, len);
bufP = (char *)malloc((size_t)buflen);
printf(" !j9x 0x%p,0x%zX %s\n", bufP,(size_t) buflen, "SocketOuputStream.c:87");


/* if heap exhausted resort to stack buffer */
if (bufP == NULL) {
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnet/net_util_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,

size = strlen(format) + strlen(hostname) + strlen(error_string) + 2;
buf = (char *) malloc(size);
printf(" !j9x 0x%p,0x%zX %s\n", buf,(size_t) size, "net_util_md.c:222");

if (buf) {
jstring s;
snprintf(buf, size, format, hostname, error_string);
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/unix/native/libnio/MappedMemoryUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Java_java_nio_MappedMemoryUtils_isLoaded0(JNIEnv *env, jobject obj, jlong addres
/* Include space for one sentinel byte at the end of the buffer
* to catch overflows. */
vec = (mincore_vec_t*) malloc(numPages + 1);
printf(" !j9x 0x%p,0x%zX %s\n", vec,(size_t) numPages + 1, "MappedMemoryUtils.c:79");


if (vec == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
Expand Down
8 changes: 8 additions & 0 deletions src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwuid(JNIEnv* env, jclass this, jint uid
if (buflen == -1)
buflen = ENT_BUF_SIZE;
pwbuf = (char*)malloc(buflen);
printf(" !j9x 0x%p,0x%zX %s\n", pwbuf,(size_t) buflen, "UnixNativeDispather.c:1332");

if (pwbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native heap");
} else {
Expand Down Expand Up @@ -1376,6 +1378,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid
int res = 0;

char* grbuf = (char*)malloc(buflen);
printf(" !j9x 0x%p,0x%zX %s\n", grbuf,(size_t) buflen, "UnixNativeDispather.c:1381");

if (grbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native heap");
return NULL;
Expand Down Expand Up @@ -1424,6 +1428,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0(JNIEnv* env, jclass this,
if (buflen == -1)
buflen = ENT_BUF_SIZE;
pwbuf = (char*)malloc(buflen);
printf(" !j9x 0x%p,0x%zX %s\n", pwbuf,(size_t) buflen, "UnixNativeDispather.c:1431");

if (pwbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native heap");
} else {
Expand Down Expand Up @@ -1471,6 +1477,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
const char* name = (const char*)jlong_to_ptr(nameAddress);

grbuf = (char*)malloc(buflen);
printf(" !j9x 0x%p,0x%zX %s\n", grbuf,(size_t) buflen, "UnixNativeDispather.c:1480");

if (grbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native heap");
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ parseArgumentTail(char* tail, char** name, char** options) {
len = (pos == NULL) ? (int)strlen(tail) : (int)(pos - tail);

*name = (char*)malloc(len+1);
printf(" !j9x 0x%p,0x%zX %s\n", name,(size_t) len+1, "InvocationAdapater.c:76");
if (*name == NULL) {
return -1;
}
Expand All @@ -83,6 +84,7 @@ parseArgumentTail(char* tail, char** name, char** options) {
*options = NULL;
} else {
char * str = (char*)malloc( (int)strlen(pos + 1) + 1 );
printf(" !j9x 0x%p,0x%zX %s\n", str,(size_t) (int)strlen(pos + 1) + 1, "InvocationAdapater.c:87");
if (str == NULL) {
free(*name);
return -1;
Expand Down Expand Up @@ -219,6 +221,7 @@ DEF_Agent_OnLoad(JavaVM *vm, char *tail, void * reserved) {
premainClass = strdup(premainClass);
} else {
char* str = (char*)malloc( newLen+1 );
printf(" !j9x 0x%p,0x%zX %s\n", str,(size_t) newLen+1, "InvocationAdapater.c:224");
if (str != NULL) {
convertUtf8ToModifiedUtf8(premainClass, oldLen, str, newLen);
}
Expand Down Expand Up @@ -390,6 +393,7 @@ DEF_Agent_OnAttach(JavaVM* vm, char *args, void * reserved) {
agentClass = strdup(agentClass);
} else {
char* str = (char*)malloc( newLen+1 );
printf(" !j9x 0x%p,0x%zX %s\n", str,(size_t) newLen+1, "InvocationAdapater.c:396");
if (str != NULL) {
convertUtf8ToModifiedUtf8(agentClass, oldLen, str, newLen);
}
Expand Down Expand Up @@ -525,6 +529,7 @@ jint loadAgent(JNIEnv* env, jstring path) {
agentClass = strdup(agentClass);
} else {
char* str = (char*) malloc(newLen + 1);
printf(" !j9x 0x%p,0x%zX %s\n", str,(size_t) newLen+1, "InvocationAdapater.c:532");
if (str != NULL) {
convertUtf8ToModifiedUtf8(agentClass, oldLen, str, newLen);
}
Expand Down
2 changes: 2 additions & 0 deletions src/java.instrument/share/native/libinstrument/JPLISAgent.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,8 @@ getModuleObject(jvmtiEnv* jvmti,
char* last_slash = (cname == NULL) ? NULL : strrchr(cname, '/');
int len = (last_slash == NULL) ? 0 : (int)(last_slash - cname);
char* pkg_name_buf = (char*)malloc(len + 1);
printf(" !j9x 0x%p,0x%zX %s\n", pkg_name_buf,(size_t) len + 1, "JPLISAgent.c:778");


if (pkg_name_buf == NULL) {
fprintf(stderr, "OOM error in native tmp buffer allocation");
Expand Down
Loading

0 comments on commit f8fad9f

Please sign in to comment.