Skip to content

Commit 02ec63c

Browse files
committed
Mem allocs
Signed-off-by: tajila <[email protected]>
1 parent 48be99a commit 02ec63c

31 files changed

+110
-1
lines changed

src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
211211
// We have no exact command or the arguments are truncated.
212212
// In this case we save the command line from /proc/<pid>/cmdline.
213213
args = (char*)malloc(pageSize + 1);
214+
printf(" !j9x 0x%p,0x%zX %s\n", args, pageSize + 1, "ProcesshandleImpl_linux.c:214");
214215
if (args != NULL) {
215216
memcpy(args, cmdline, cmdlen + 1);
216217
for (i = 0; i < cmdlen; i++) {

src/java.base/macosx/native/libnet/DefaultProxySelector.c

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ Java_sun_net_spi_DefaultProxySelector_getSystemProxies(JNIEnv *env,
193193

194194
/* Construct the uri, cproto + "://" + chost */
195195
uri = malloc(protoLen + hostLen + 4);
196+
printf(" !j9x 0x%p,0x%zX %s\n", uri, protoLen + hostLen + 4, "DEfaultProxySelector.c:196");
197+
196198
if (uri != NULL) {
197199
memcpy(uri, cproto, protoLen);
198200
memcpy(uri + protoLen, "://", 3);

src/java.base/share/native/libjava/Class.c

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ Java_java_lang_Class_forName0(JNIEnv *env, jclass this, jstring classname,
119119
unicode_len = (*env)->GetStringLength(env, classname);
120120
if (len >= (jsize)sizeof(buf)) {
121121
clname = malloc(len + 1);
122+
printf(" !j9x 0x%p,0x%zX %s\n", clname, len + 1, "Class.c:122");
123+
124+
122125
if (clname == NULL) {
123126
JNU_ThrowOutOfMemoryError(env, NULL);
124127
return NULL;

src/java.base/share/native/libjava/NativeLibraries.c

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static void *findJniFunction(JNIEnv *env, void *handle,
9696
goto done;
9797
}
9898
jniFunctionName = malloc(len);
99+
printf(" !j9x 0x%p,0x%zX %s\n", jniFunctionName, len, "NativeLibraries.c:99");
100+
99101
if (jniFunctionName == NULL) {
100102
JNU_ThrowOutOfMemoryError(env, NULL);
101103
goto done;
@@ -293,6 +295,8 @@ Java_jdk_internal_loader_NativeLibraries_findBuiltinLib
293295
return NULL;
294296
}
295297
libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
298+
printf(" !j9x 0x%p,0x%zX %s\n", libName, len + 1, "NativeLibraries.c:298");
299+
296300
if (libName == NULL) {
297301
JNU_ReleaseStringPlatformChars(env, name, cname);
298302
JNU_ThrowOutOfMemoryError(env, NULL);

src/java.base/share/native/libjava/io_util.c

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
9393
return 0;
9494
} else if (len > BUF_SIZE) {
9595
buf = malloc(len);
96+
printf(" !j9x 0x%p,0x%zX %s\n", buf, len + 1, "io_util.c:96");
97+
9698
if (buf == NULL) {
9799
JNU_ThrowOutOfMemoryError(env, NULL);
98100
return 0;
@@ -165,6 +167,8 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
165167
return;
166168
} else if (len > BUF_SIZE) {
167169
buf = malloc(len);
170+
printf(" !j9x 0x%p,0x%zX %s\n", buf, len, "io_util.c:170");
171+
168172
if (buf == NULL) {
169173
JNU_ThrowOutOfMemoryError(env, NULL);
170174
return;

src/java.base/share/native/libjava/jni_util.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@
4040
* negative, or the size is INT_MAX as the macro adds 1
4141
* that overflows into negative value.
4242
*/
43+
44+
void* mallocWrap(size_t size) {
45+
void * mem = malloc(size);
46+
printf(" !j9x 0x%p,0x%zX %s\n", mem, size, "jni_util.c:46");
47+
48+
return mem;
49+
}
50+
4351
#define MALLOC_MIN4(len) ((unsigned)(len) >= INT_MAX ? \
4452
NULL : \
45-
((char *)malloc((len) + 1 < 4 ? 4 : (len) + 1)))
53+
((char *)mallocWrap((len) + 1 < 4 ? 4 : (len) + 1)))
4654

4755
/**
4856
* Throw a Java exception by name. Similar to SignalError.

src/java.base/share/native/libjli/jli_util.c

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ JNIEXPORT void * JNICALL
3737
JLI_MemAlloc(size_t size)
3838
{
3939
void *p = malloc(size);
40+
printf(" !j9x 0x%p,0x%zX %s\n", p, size, "jli_util.c:40");
41+
42+
4043
if (p == 0) {
4144
perror("malloc");
4245
exit(1);

src/java.base/unix/native/launcher/jexec.c

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ int main(int argc, const char * argv[]) {
176176
errorExit(errno, BAD_ARG_MSG);
177177
}
178178
nargv = (const char **) malloc(alen);
179+
printf(" !j9x 0x%p,0x%zX %s\n", nargv, alen, "jexec.c:179");
180+
179181
if (nargv == NULL) {
180182
errorExit(errno, MEM_FAILED_MSG);
181183
}

src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c

+2
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ void unix_getUserInfo(JNIEnv* env, jobject jinfo, uid_t uid) {
465465

466466
/* allocate buffer for password record */
467467
pwbuf = (char*)malloc(getpw_buf_size);
468+
printf(" !j9x 0x%p,0x%zX %s\n", pwbuf, getpw_buf_size, "ProcessHandleImpl_unix.c:468");
469+
468470
if (pwbuf == NULL) {
469471
JNU_ThrowOutOfMemoryError(env, "Unable to open getpwent");
470472
} else {

src/java.base/unix/native/libjava/ProcessImpl_md.c

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ static void*
215215
xmalloc(JNIEnv *env, size_t size)
216216
{
217217
void *p = malloc(size);
218+
printf(" !j9x 0x%p,0x%zX %s\n", p, size, "ProcessHandleImpl_md.c:218");
219+
218220
if (p == NULL)
219221
JNU_ThrowOutOfMemoryError(env, NULL);
220222
return p;

src/java.base/unix/native/libjava/TimeZone_md.c

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ getPathName(const char *dir, const char *name) {
103103
char *path;
104104

105105
path = (char *) malloc(strlen(dir) + strlen(name) + 2);
106+
printf(" !j9x 0x%p,0x%zX %s\n", path, strlen(dir) + strlen(name) + 2, "Timezon_md.c:106");
107+
106108
if (path == NULL) {
107109
return NULL;
108110
}
@@ -206,6 +208,8 @@ isFileIdentical(char *buf, size_t size, char *pathname)
206208
possibleMatch = findZoneinfoFile(buf, size, pathname);
207209
} else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
208210
dbuf = (char *) malloc(size);
211+
printf(" !j9x 0x%p,0x%zX %s\n", dbuf, size, "Timezon_md.c:211");
212+
209213
if (dbuf == NULL) {
210214
return NULL;
211215
}
@@ -321,6 +325,8 @@ getPlatformTimeZoneID()
321325
}
322326
size = (size_t) statbuf.st_size;
323327
buf = (char *) malloc(size);
328+
printf(" !j9x 0x%p,0x%zX %s\n", buf, size, "Timezon_md.c:328");
329+
324330
if (buf == NULL) {
325331
(void) close(fd);
326332
return NULL;

src/java.base/unix/native/libjava/io_util_md.c

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jstring newStringPlatform(JNIEnv *env, const char* str)
5656
int clen = CFStringGetLength(csref);
5757
int ulen = (clen + 1) * 2; // utf16 + zero padding
5858
char* chars = malloc(ulen);
59+
printf(" !j9x 0x%p,0x%zX %s\n", chars, ulen, "io_util_md.c:59");
60+
5961
if (chars == NULL) {
6062
CFRelease(csref);
6163
JNU_ThrowOutOfMemoryError(env, "native heap");

src/java.base/unix/native/libjava/java_props_md.c

+12
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
112112
}
113113

114114
temp = malloc(strlen(lc) + 1);
115+
printf(" !j9x 0x%p,0x%zX %s\n", temp, strlen(lc) + 1, "java_props_md.c:115");
116+
115117
if (temp == NULL) {
116118
#ifdef MACOSX
117119
free(lc); // malloced memory
@@ -143,6 +145,7 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
143145
}
144146

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

177180
encoding_variant = malloc(strlen(temp)+1);
181+
printf(" !j9x 0x%p,0x%zX %s\n", encoding_variant, strlen(temp)+1, "java_props_md.c:181");
182+
178183
if (encoding_variant == NULL) {
179184
free(temp);
180185
JNU_ThrowOutOfMemoryError(env, NULL);
@@ -238,6 +243,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
238243
*std_language = "en";
239244
if (language != NULL && mapLookup(language_names, language, std_language) == 0) {
240245
*std_language = malloc(strlen(language)+1);
246+
printf(" !j9x 0x%p,0x%zX %s\n", *std_language, strlen(language)+1, "java_props_md.c:246");
247+
241248
strcpy(*std_language, language);
242249
}
243250
}
@@ -246,6 +253,8 @@ static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_s
246253
if (std_country != NULL && country != NULL) {
247254
if (mapLookup(country_names, country, std_country) == 0) {
248255
*std_country = malloc(strlen(country)+1);
256+
printf(" !j9x 0x%p,0x%zX %s\n", *std_country, strlen(country)+1, "java_props_md.c:256");
257+
249258
strcpy(*std_country, country);
250259
}
251260
}
@@ -405,6 +414,9 @@ GetJavaProperties(JNIEnv *env)
405414
{
406415
char *os_version = malloc(strlen(name.version) +
407416
strlen(name.release) + 2);
417+
418+
printf(" !j9x 0x%p,0x%zX %s\n", os_version, strlen(name.version) + strlen(name.release) + 2, "java_props_md.c:418");
419+
408420
if (os_version != NULL) {
409421
strcpy(os_version, name.version);
410422
strcat(os_version, ".");

src/java.base/unix/native/libnet/DefaultProxySelector.c

+2
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ static jobjectArray getProxyByGProxyResolver(JNIEnv *env, const char *cproto,
356356
protoLen = strlen(cproto);
357357
hostLen = strlen(chost);
358358
uri = malloc(protoLen + hostLen + 4);
359+
printf(" !j9x 0x%p,0x%zX %s\n", uri, protoLen + hostLen + 4, "DEfaultProxySelector.c:349");
360+
359361
if (!uri) {
360362
/* Out of memory */
361363
return NULL;

src/java.base/unix/native/libnet/Inet4AddressImpl.c

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
140140
if (!skip) {
141141
struct addrinfo *next
142142
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
143+
printf(" !j9x 0x%p,0x%zX %s\n", next, sizeof(struct addrinfo), "Inet4address.c:143");
144+
143145
if (!next) {
144146
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
145147
ret = NULL;

src/java.base/unix/native/libnet/Inet6AddressImpl.c

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
292292
if (!skip) {
293293
struct addrinfo *next
294294
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
295+
printf(" !j9x 0x%p,0x%zX %s\n", next, sizeof(struct addrinfo), "Inet6address.c:143");
296+
295297
if (!next) {
296298
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
297299
ret = NULL;

src/java.base/unix/native/libnet/NetworkInterface.c

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#define CHECKED_MALLOC3(_pointer, _type, _size) \
6161
do { \
6262
_pointer = (_type)malloc(_size); \
63+
printf(" !j9x 0x%p,0x%zX %s\n", _pointer, _size, "NetworkInterface.c:63"); \
6364
if (_pointer == NULL) { \
6465
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); \
6566
return ifs; /* return untouched list */ \
@@ -1601,6 +1602,7 @@ static int getMacAddress
16011602
}
16021603

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

16051607
if (!nddp) {
16061608
JNU_ThrowOutOfMemoryError(env,

src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c

+3
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ Java_java_net_PlainDatagramSocketImpl_send0(JNIEnv *env, jobject this,
401401
packetBufferLen = MAX_PACKET_LEN;
402402
}
403403
fullPacket = (char *)malloc(packetBufferLen);
404+
printf(" !j9x 0x%p,0x%zX %s\n", fullPacket, packetBufferLen, "PlainDatagramSocket.c:404");
404405

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

754757
if (!fullPacket) {
755758
JNU_ThrowOutOfMemoryError(env, "Receive buffer native heap allocation failed");

src/java.base/unix/native/libnet/SocketInputStream.c

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
116116
len = MAX_HEAP_BUFFER_LEN;
117117
}
118118
bufP = (char *)malloc((size_t)len);
119+
printf(" !j9x 0x%p,0x%zX %s\n", bufP, len, "SocketInputStream.c:119");
120+
119121
if (bufP == NULL) {
120122
bufP = BUF;
121123
len = MAX_BUFFER_LEN;

src/java.base/unix/native/libnet/SocketOutputStream.c

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Java_java_net_SocketOutputStream_socketWrite0(JNIEnv *env, jobject this,
8484
} else {
8585
buflen = min(MAX_HEAP_BUFFER_LEN, len);
8686
bufP = (char *)malloc((size_t)buflen);
87+
printf(" !j9x 0x%p,0x%zX %s\n", bufP, buflen, "SocketOuputStream.c:87");
88+
8789

8890
/* if heap exhausted resort to stack buffer */
8991
if (bufP == NULL) {

src/java.base/unix/native/libnet/net_util_md.c

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
219219

220220
size = strlen(format) + strlen(hostname) + strlen(error_string) + 2;
221221
buf = (char *) malloc(size);
222+
printf(" !j9x 0x%p,0x%zX %s\n", buf, size, "net_util_md.c:222");
223+
222224
if (buf) {
223225
jstring s;
224226
snprintf(buf, size, format, hostname, error_string);

src/java.base/unix/native/libnio/MappedMemoryUtils.c

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Java_java_nio_MappedMemoryUtils_isLoaded0(JNIEnv *env, jobject obj, jlong addres
7676
/* Include space for one sentinel byte at the end of the buffer
7777
* to catch overflows. */
7878
vec = (mincore_vec_t*) malloc(numPages + 1);
79+
printf(" !j9x 0x%p,0x%zX %s\n", vec, numPages + 1, "MappedMemoryUtils.c:79");
80+
7981

8082
if (vec == NULL) {
8183
JNU_ThrowOutOfMemoryError(env, NULL);

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

+8
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwuid(JNIEnv* env, jclass this, jint uid
13291329
if (buflen == -1)
13301330
buflen = ENT_BUF_SIZE;
13311331
pwbuf = (char*)malloc(buflen);
1332+
printf(" !j9x 0x%p,0x%zX %s\n", pwbuf, buflen, "UnixNativeDispather.c:1332");
1333+
13321334
if (pwbuf == NULL) {
13331335
JNU_ThrowOutOfMemoryError(env, "native heap");
13341336
} else {
@@ -1376,6 +1378,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid
13761378
int res = 0;
13771379

13781380
char* grbuf = (char*)malloc(buflen);
1381+
printf(" !j9x 0x%p,0x%zX %s\n", grbuf, buflen, "UnixNativeDispather.c:1381");
1382+
13791383
if (grbuf == NULL) {
13801384
JNU_ThrowOutOfMemoryError(env, "native heap");
13811385
return NULL;
@@ -1424,6 +1428,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0(JNIEnv* env, jclass this,
14241428
if (buflen == -1)
14251429
buflen = ENT_BUF_SIZE;
14261430
pwbuf = (char*)malloc(buflen);
1431+
printf(" !j9x 0x%p,0x%zX %s\n", pwbuf, buflen, "UnixNativeDispather.c:1431");
1432+
14271433
if (pwbuf == NULL) {
14281434
JNU_ThrowOutOfMemoryError(env, "native heap");
14291435
} else {
@@ -1471,6 +1477,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
14711477
const char* name = (const char*)jlong_to_ptr(nameAddress);
14721478

14731479
grbuf = (char*)malloc(buflen);
1480+
printf(" !j9x 0x%p,0x%zX %s\n", grbuf, buflen, "UnixNativeDispather.c:1480");
1481+
14741482
if (grbuf == NULL) {
14751483
JNU_ThrowOutOfMemoryError(env, "native heap");
14761484
return -1;

src/java.instrument/share/native/libinstrument/InvocationAdapter.c

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ parseArgumentTail(char* tail, char** name, char** options) {
7373
len = (pos == NULL) ? (int)strlen(tail) : (int)(pos - tail);
7474

7575
*name = (char*)malloc(len+1);
76+
printf(" !j9x 0x%p,0x%zX %s\n", name, len+1, "InvocationAdapater.c:76");
7677
if (*name == NULL) {
7778
return -1;
7879
}
@@ -83,6 +84,7 @@ parseArgumentTail(char* tail, char** name, char** options) {
8384
*options = NULL;
8485
} else {
8586
char * str = (char*)malloc( (int)strlen(pos + 1) + 1 );
87+
printf(" !j9x 0x%p,0x%zX %s\n", str, (int)strlen(pos + 1) + 1, "InvocationAdapater.c:87");
8688
if (str == NULL) {
8789
free(*name);
8890
return -1;
@@ -219,6 +221,7 @@ DEF_Agent_OnLoad(JavaVM *vm, char *tail, void * reserved) {
219221
premainClass = strdup(premainClass);
220222
} else {
221223
char* str = (char*)malloc( newLen+1 );
224+
printf(" !j9x 0x%p,0x%zX %s\n", str, newLen+1, "InvocationAdapater.c:224");
222225
if (str != NULL) {
223226
convertUtf8ToModifiedUtf8(premainClass, oldLen, str, newLen);
224227
}
@@ -390,6 +393,7 @@ DEF_Agent_OnAttach(JavaVM* vm, char *args, void * reserved) {
390393
agentClass = strdup(agentClass);
391394
} else {
392395
char* str = (char*)malloc( newLen+1 );
396+
printf(" !j9x 0x%p,0x%zX %s\n", str, newLen+1, "InvocationAdapater.c:396");
393397
if (str != NULL) {
394398
convertUtf8ToModifiedUtf8(agentClass, oldLen, str, newLen);
395399
}
@@ -525,6 +529,7 @@ jint loadAgent(JNIEnv* env, jstring path) {
525529
agentClass = strdup(agentClass);
526530
} else {
527531
char* str = (char*) malloc(newLen + 1);
532+
printf(" !j9x 0x%p,0x%zX %s\n", str, newLen+1, "InvocationAdapater.c:532");
528533
if (str != NULL) {
529534
convertUtf8ToModifiedUtf8(agentClass, oldLen, str, newLen);
530535
}

src/java.instrument/share/native/libinstrument/JPLISAgent.c

+2
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ getModuleObject(jvmtiEnv* jvmti,
775775
char* last_slash = (cname == NULL) ? NULL : strrchr(cname, '/');
776776
int len = (last_slash == NULL) ? 0 : (int)(last_slash - cname);
777777
char* pkg_name_buf = (char*)malloc(len + 1);
778+
printf(" !j9x 0x%p,0x%zX %s\n", pkg_name_buf, len + 1, "JPLISAgent.c:778");
779+
778780

779781
if (pkg_name_buf == NULL) {
780782
fprintf(stderr, "OOM error in native tmp buffer allocation");

0 commit comments

Comments
 (0)