Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/jdk.jdwp.agent/share/native/libjdwp/debugInit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -890,8 +890,6 @@ printUsage(void)
" everything = 0xfff"));

TTY_MESSAGE((
"debugflags=flags debug flags (bitmask) none\n"
" USE_ITERATE_THROUGH_HEAP 0x01\n"
"\n"
"Environment Variables\n"
"---------------------\n"
Expand Down Expand Up @@ -1192,13 +1190,6 @@ parseOptions(char *options)
}
/*LINTED*/
logflags = (unsigned)strtol(current, NULL, 0);
} else if (strcmp(buf, "debugflags") == 0) {
/*LINTED*/
if (!get_tok(&str, current, (int)(end - current), ',')) {
goto syntax_error;
}
/*LINTED*/
gdata->debugflags = (unsigned)strtol(current, NULL, 0);
} else if ( strcmp(buf, "suspend")==0 ) {
if ( !get_boolean(&str, &suspendOnInit) ) {
goto syntax_error;
Expand Down
102 changes: 20 additions & 82 deletions src/jdk.jdwp.agent/share/native/libjdwp/util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -2730,10 +2730,6 @@ typedef struct ClassCountData {
jvmtiError error;
} ClassCountData;

/* Two different cbObjectCounter's, one for FollowReferences, one for
* IterateThroughHeap. Pick a card, any card.
*/

/* Callback for object count heap traversal (heap_reference_callback) */
static jint JNICALL
cbObjectCounterFromRef(jvmtiHeapReferenceKind reference_kind,
Expand Down Expand Up @@ -2795,38 +2791,6 @@ cbObjectCounterFromRef(jvmtiHeapReferenceKind reference_kind,
return JVMTI_VISIT_OBJECTS;
}

/* Callback for instance count heap traversal (heap_iteration_callback) */
static jint JNICALL
cbObjectCounter(jlong class_tag, jlong size, jlong* tag_ptr, jint length,
void* user_data)
{
ClassCountData *data;
int index;

/* Check data structure */
data = (ClassCountData*)user_data;
if (data == NULL) {
return JVMTI_VISIT_ABORT;
}

/* Classes with no tag should be filtered out. */
if ( class_tag == (jlong)0 ) {
data->error = AGENT_ERROR_INTERNAL;
return JVMTI_VISIT_ABORT;
}

/* Class tag is actually an index into data arrays */
index = CLASSTAG2INDEX(class_tag);
if (index < 0 || index >= data->classCount) {
data->error = AGENT_ERROR_ILLEGAL_ARGUMENT;
return JVMTI_VISIT_ABORT;
}

/* Bump instance count on this class */
data->counts[index]++;
return JVMTI_VISIT_OBJECTS;
}

/* Get instance counts for a set of classes */
jvmtiError
classInstanceCounts(jint classCount, jclass *classes, jlong *counts)
Expand Down Expand Up @@ -2879,53 +2843,27 @@ classInstanceCounts(jint classCount, jclass *classes, jlong *counts)
/* Clear out callbacks structure */
(void)memset(&heap_callbacks,0,sizeof(heap_callbacks));

/* Check debug flags to see how to do this. */
if ( (gdata->debugflags & USE_ITERATE_THROUGH_HEAP) == 0 ) {

/* Using FollowReferences only gives us live objects, but we
* need to tag the objects to avoid counting them twice since
* the callback is per reference.
* The jclass objects have been tagged with their index in the
* supplied list, and that tag may flip to negative if it
* is also an object of interest.
* All other objects being counted that weren't in the
* supplied classes list will have a negative classCount
* tag value. So all objects counted will have negative tags.
* If the absolute tag value is an index in the supplied
* list, then it's one of the supplied classes.
*/
data.negObjTag = -INDEX2CLASSTAG(classCount);

/* Setup callbacks, only using object reference callback */
heap_callbacks.heap_reference_callback = &cbObjectCounterFromRef;

/* Follow references, no initiating object, tagged classes only */
error = JVMTI_FUNC_PTR(jvmti,FollowReferences)
(jvmti, JVMTI_HEAP_FILTER_CLASS_UNTAGGED,
NULL, NULL, &heap_callbacks, &data);

} else {

/* Using IterateThroughHeap means that we will visit each object
* once, so no special tag tricks here. Just simple counting.
* However in this case the object might not be live, so we do
* a GC beforehand to make sure we minimize this.
*/

/* FIXUP: Need some kind of trigger here to avoid excessive GC's? */
error = JVMTI_FUNC_PTR(jvmti,ForceGarbageCollection)(jvmti);
if ( error != JVMTI_ERROR_NONE ) {

/* Setup callbacks, just need object callback */
heap_callbacks.heap_iteration_callback = &cbObjectCounter;
/* Using FollowReferences only gives us live objects, but we
* need to tag the objects to avoid counting them twice since
* the callback is per reference.
* The jclass objects have been tagged with their index in the
* supplied list, and that tag may flip to negative if it
* is also an object of interest.
* All other objects being counted that weren't in the
* supplied classes list will have a negative classCount
* tag value. So all objects counted will have negative tags.
* If the absolute tag value is an index in the supplied
* list, then it's one of the supplied classes.
*/
data.negObjTag = -INDEX2CLASSTAG(classCount);

/* Iterate through entire heap, tagged classes only */
error = JVMTI_FUNC_PTR(jvmti,IterateThroughHeap)
(jvmti, JVMTI_HEAP_FILTER_CLASS_UNTAGGED,
NULL, &heap_callbacks, &data);
/* Setup callbacks, only using object reference callback */
heap_callbacks.heap_reference_callback = &cbObjectCounterFromRef;

}
}
/* Follow references, no initiating object, tagged classes only */
error = JVMTI_FUNC_PTR(jvmti,FollowReferences)
(jvmti, JVMTI_HEAP_FILTER_CLASS_UNTAGGED,
NULL, NULL, &heap_callbacks, &data);

/* Use data error if needed */
if ( error == JVMTI_ERROR_NONE ) {
Expand Down
8 changes: 1 addition & 7 deletions src/jdk.jdwp.agent/share/native/libjdwp/util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -92,12 +92,6 @@ typedef struct {
jboolean quiet;
jboolean jvmti_data_dump; /* If true, then support JVMTI DATA_DUMP_REQUEST events. */

/* Debug flags (bit mask) */
int debugflags;

/* Possible debug flags */
#define USE_ITERATE_THROUGH_HEAP 0X001

char * options;

jclass classClass;
Expand Down