@@ -1480,23 +1480,7 @@ static CommandResult createReply(Packet packet, JDWPContext context) {
14801480 return new CommandResult (reply );
14811481 }
14821482
1483- if (!method .hasVariableTable ()) {
1484- reply .errorCode (ErrorCodes .ABSENT_INFORMATION );
1485- return new CommandResult (reply );
1486- }
1487-
1488- KlassRef [] params = method .getParameters ();
1489- int argCnt = 0 ; // the number of words in the frame used by the arguments
1490- for (KlassRef klass : params ) {
1491- if (klass .isPrimitive ()) {
1492- byte tag = klass .getTagConstant ();
1493- if (tag == TagConstants .DOUBLE || tag == TagConstants .LONG ) {
1494- argCnt += 2 ;
1495- } else {
1496- argCnt ++;
1497- }
1498- }
1499- }
1483+ int argCnt = getArgCount (method .getSignatureAsString ());
15001484 LocalRef [] locals = method .getLocalVariableTable ().getLocals ();
15011485
15021486 reply .writeInt (argCnt );
@@ -1583,24 +1567,8 @@ static CommandResult createReply(Packet packet, JDWPContext context) {
15831567 if (method == null ) {
15841568 return new CommandResult (reply );
15851569 }
1586-
1587- if (!method .hasVariableTable ()) {
1588- reply .errorCode (ErrorCodes .ABSENT_INFORMATION );
1589- return new CommandResult (reply );
1590- }
1591-
1592- KlassRef [] params = method .getParameters ();
1593- int argCnt = 0 ; // the number of words in the frame used by the arguments
1594- for (KlassRef klass : params ) {
1595- if (klass .isPrimitive ()) {
1596- byte tag = klass .getTagConstant ();
1597- if (tag == TagConstants .DOUBLE || tag == TagConstants .LONG ) {
1598- argCnt += 2 ;
1599- } else {
1600- argCnt ++;
1601- }
1602- }
1603- }
1570+ // the number of words in the frame used by the arguments
1571+ int argCnt = getArgCount (method .getSignatureAsString ());
16041572 LocalRef [] locals = method .getLocalVariableTable ().getLocals ();
16051573 LocalRef [] genericLocals = method .getLocalVariableTypeTable ().getLocals ();
16061574
@@ -3240,6 +3208,70 @@ private static int checkSyntheticFlag(int modBits) {
32403208 return mod ;
32413209 }
32423210
3211+ private static int getArgCount (String signature ) {
3212+ int startIndex = signature .indexOf ('(' ) + 1 ;
3213+ int endIndex = signature .indexOf (')' );
3214+ String parameterSig = signature .substring (startIndex , endIndex );
3215+ int currentCount = 0 ;
3216+ int currentIndex = 0 ;
3217+ char [] charArray = parameterSig .toCharArray ();
3218+ while (currentIndex < charArray .length ) {
3219+ switch (charArray [currentIndex ]) {
3220+ case 'D' :
3221+ case 'J' : {
3222+ currentCount += 2 ;
3223+ currentIndex ++;
3224+ break ;
3225+ }
3226+ case 'B' :
3227+ case 'C' :
3228+ case 'F' :
3229+ case 'I' :
3230+ case 'S' :
3231+ case 'Z' : {
3232+ currentCount ++;
3233+ currentIndex ++;
3234+ break ;
3235+ }
3236+ case 'L' :
3237+ currentCount ++;
3238+ currentIndex = parameterSig .indexOf (';' , currentIndex ) + 1 ;
3239+ break ;
3240+ case 'T' :
3241+ throw new RuntimeException ("unexpected type variable" );
3242+ case '[' :
3243+ currentCount ++;
3244+ currentIndex += parseArrayType (parameterSig , charArray , currentIndex + 1 );
3245+ break ;
3246+ default :
3247+ throw new RuntimeException ("should not reach here" );
3248+ }
3249+ }
3250+ return currentCount ;
3251+ }
3252+
3253+ private static int parseArrayType (String signature , char [] charArray , int currentIndex ) {
3254+ switch (charArray [currentIndex ]) {
3255+ case 'D' :
3256+ case 'J' :
3257+ case 'B' :
3258+ case 'C' :
3259+ case 'F' :
3260+ case 'I' :
3261+ case 'S' :
3262+ case 'Z' :
3263+ return 2 ;
3264+ case 'L' :
3265+ return 2 + signature .indexOf (';' , currentIndex ) - currentIndex ;
3266+ case 'T' :
3267+ throw new RuntimeException ("unexpected type variable" );
3268+ case '[' :
3269+ return 1 + parseArrayType (signature , charArray , currentIndex + 1 );
3270+ default :
3271+ throw new RuntimeException ("should not reach here" );
3272+ }
3273+ }
3274+
32433275 private static KlassRef verifyRefType (long refTypeId , PacketStream reply , JDWPContext context ) {
32443276 KlassRef klass ;
32453277 try {
0 commit comments