On Thu, 1 Oct 2026 23:08:42 GMT, Serguei Spitsyn <[email protected]> wrote:

> When the JVMTI `IterateThroughHeap` has a class filter then the flattened 
> value objects contained in the fields of filtered class objects are not 
> reported. The fix is:
>  - If the object has flattened fields, visit and report them as heap objects 
> even though this object was not reported.
> 
> The update adds new test with a needed coverage:
>   
> `test/hotspot/jtreg/serviceability/jvmti/valhalla/Heapwalking/FlatClassFilterTest.java`
> 
> Testing:
>  - check new test is failing without fix and is passing with the fix
>  - TBD: run mach5 tiers 1-6
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

For more detailed fix explanation...
The fix is in the function `IterateThroughHeapObjectClosure::visit_object()`.
There were two early returns from this function:

-  if (is_filtered_by_klass_filter(obj, klass())) return;

and:

-  if (is_filtered_by_heap_filter(wrapper.obj_tag(), wrapper.klass_tag(), 
heap_filter())) {
-    return;
-  }

The fix is to avoid these early returns but invoke the callback conditionally 
like below:

+  if (!is_filtered_by_klass_filter(obj, klass())) { // apply class filter
+    // prepare for callback
+    CallbackWrapper wrapper(tag_map(), obj);
+
+    // check if filtered by the heap filter
+    if (!is_filtered_by_heap_filter(wrapper.obj_tag(), wrapper.klass_tag(), 
heap_filter())) {
+       <invoke the callbacks if necessary>

Then the following block at the end won't be over-passed:

1347   if (obj.klass()->is_instance_klass()) {
1348     if (InstanceKlass::cast(obj.klass())->has_flat_fields()) {
1349       visit_flat_fields(obj);
1350       // check if iteration has been halted
1351       if (is_iteration_aborted()) {
1352         return;
1353       }
1354     }
1355   }
1356   // If the object is flat array, report all elements as heap objects.
1357   if (is_array && obj.obj()->is_flatArray()) {
1358     assert(!obj.is_flat(), "Array object cannot be flattened");
1359     visit_flat_array_elements(obj);
1360   }

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33172#issuecomment-6023933366

Reply via email to