|
1 | 1 | /*
|
2 |
| - * Copyright (C) 2011-2021 Samuel Audet |
| 2 | + * Copyright (C) 2011-2022 Samuel Audet |
3 | 3 | *
|
4 | 4 | * Licensed either under the Apache License, Version 2.0, or (at your option)
|
5 | 5 | * under the terms of the GNU General Public License as published by
|
@@ -552,21 +552,38 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver
|
552 | 552 | out.println(" char* s;");
|
553 | 553 | out.println(" int n;");
|
554 | 554 | out.println(" if ((n = pread(fd, line, sizeof(line), 0)) > 0 && (s = (char*)memchr(line, ' ', n)) != NULL) {");
|
555 |
| - out.println(" size = (jlong)(atoll(s + 1) * getpagesize());"); |
| 555 | + out.println(" size = (jlong)atoll(s + 1);"); |
| 556 | + out.println(" if ((s = (char*)memchr(s + 1, ' ', n)) != NULL) {"); |
| 557 | + out.println(" size -= (jlong)atoll(s + 1);"); |
| 558 | + out.println(" }"); |
556 | 559 | out.println(" }");
|
| 560 | + out.println(" size *= (jlong)getpagesize();"); |
557 | 561 | out.println(" // no close(fd);");
|
558 | 562 | out.println(" }");
|
559 | 563 | out.println("#elif defined(__APPLE__)");
|
560 |
| - out.println(" task_basic_info info;"); |
561 |
| - out.println(" mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;"); |
562 |
| - out.println(" if (task_info(current_task(), TASK_BASIC_INFO, (task_info_t)&info, &count) == KERN_SUCCESS) {"); |
563 |
| - out.println(" size = (jlong)info.resident_size;"); |
| 564 | + out.println(" task_vm_info_data_t info;"); |
| 565 | + out.println(" mach_msg_type_number_t count = TASK_VM_INFO_COUNT;"); |
| 566 | + out.println(" if (task_info(current_task(), TASK_VM_INFO, (task_info_t)&info, &count) == KERN_SUCCESS) {"); |
| 567 | + out.println(" size = (jlong)info.internal;"); |
564 | 568 | out.println(" }");
|
565 | 569 | out.println("#elif defined(_WIN32)");
|
566 |
| - out.println(" PROCESS_MEMORY_COUNTERS counters;"); |
567 |
| - out.println(" if (GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters))) {"); |
568 |
| - out.println(" size = (jlong)counters.WorkingSetSize;"); |
| 570 | + out.println(" DWORD length = sizeof(PSAPI_WORKING_SET_INFORMATION);"); |
| 571 | + out.println(" PSAPI_WORKING_SET_INFORMATION *info = (PSAPI_WORKING_SET_INFORMATION*)malloc(length);"); |
| 572 | + out.println(" BOOL success = QueryWorkingSet(GetCurrentProcess(), info, length);"); |
| 573 | + out.println(" while (!success && GetLastError() == ERROR_BAD_LENGTH) {"); |
| 574 | + out.println(" length = sizeof(PSAPI_WORKING_SET_INFORMATION) + info->NumberOfEntries * sizeof(PSAPI_WORKING_SET_BLOCK);"); |
| 575 | + out.println(" info = (PSAPI_WORKING_SET_INFORMATION*)realloc(info, length);"); |
| 576 | + out.println(" success = QueryWorkingSet(GetCurrentProcess(), info, length);"); |
569 | 577 | out.println(" }");
|
| 578 | + out.println(" if (success && info != NULL) {"); |
| 579 | + out.println(" for (DWORD i = 0; i < info->NumberOfEntries; i++) {"); |
| 580 | + out.println(" size += !info->WorkingSetInfo[i].Shared;"); |
| 581 | + out.println(" }"); |
| 582 | + out.println(" }"); |
| 583 | + out.println(" SYSTEM_INFO sysinfo;"); |
| 584 | + out.println(" GetSystemInfo(&sysinfo);"); |
| 585 | + out.println(" size *= (jlong)sysinfo.dwPageSize;"); |
| 586 | + out.println(" free(info);"); |
570 | 587 | out.println("#endif");
|
571 | 588 | out.println(" return size;");
|
572 | 589 | out.println("}");
|
|
0 commit comments