@@ -154,6 +154,14 @@ void JPGarbageCollection::init(JPJavaFrame& frame)
154
154
_SystemClass = (jclass) frame.NewGlobalRef (frame.FindClass (" java/lang/System" ));
155
155
_gcMethodID = frame.GetStaticMethodID (_SystemClass, " gc" , " ()V" );
156
156
157
+ jclass ctxt = frame.getContext ()->m_ContextClass .get ();
158
+ _ContextClass = ctxt;
159
+ _totalMemoryID = frame.GetStaticMethodID (ctxt, " getTotalMemory" , " ()J" );
160
+ _freeMemoryID = frame.GetStaticMethodID (ctxt, " getFreeMemory" , " ()J" );
161
+ _maxMemoryID = frame.GetStaticMethodID (ctxt, " getMaxMemory" , " ()J" );
162
+ _usedMemoryID = frame.GetStaticMethodID (ctxt, " getUsedMemory" , " ()J" );
163
+ _heapMemoryID = frame.GetStaticMethodID (ctxt, " getHeapMemory" , " ()J" );
164
+
157
165
running = true ;
158
166
high_water = getWorkingSize ();
159
167
limit = high_water + DELTA_LIMIT;
@@ -237,10 +245,24 @@ void JPGarbageCollection::onEnd()
237
245
Py_ssize_t pred = current + 2 * (current - last);
238
246
last = current;
239
247
if ((Py_ssize_t) pred > (Py_ssize_t) limit)
248
+ {
240
249
run_gc = 2 ;
250
+ limit = high_water + (high_water>>3 ) + 8 * (current - last);
251
+ }
241
252
242
- // printf("consider gc %d (%ld, %ld, %ld, %ld) %ld\n", run_gc,
243
- // current, low_water, high_water, limit, limit - pred);
253
+ #if 0
254
+ {
255
+ JPJavaFrame frame = JPJavaFrame::outer(m_Context);
256
+ jlong totalMemory = frame.CallStaticLongMethodA(_ContextClass, _totalMemoryID, nullptr);
257
+ jlong freeMemory = frame.CallStaticLongMethodA(_ContextClass, _freeMemoryID, nullptr);
258
+ jlong maxMemory = frame.CallStaticLongMethodA(_ContextClass, _maxMemoryID, nullptr);
259
+ jlong usedMemory = frame.CallStaticLongMethodA(_ContextClass, _usedMemoryID, nullptr);
260
+ jlong heapMemory = frame.CallStaticLongMethodA(_ContextClass, _heapMemoryID, nullptr);
261
+ printf("consider gc run=%d (current=%ld, low=%ld, high=%ld, limit=%ld) %ld\n", run_gc,
262
+ current, low_water, high_water, limit, limit - pred);
263
+ printf(" java total=%ld free=%ld max=%ld used=%ld heap=%ld\n", totalMemory, freeMemory, maxMemory, usedMemory, heapMemory);
264
+ }
265
+ #endif
244
266
245
267
if (run_gc > 0 )
246
268
{
0 commit comments