< prev index next >

src/java.base/share/native/libverify/check_code.c

Print this page

3707 
3708 /*
3709  * Need to scan the entire signature to find the result type because
3710  * types in the arg list and the result type could contain embedded ')'s.
3711  */
3712 static const char* get_result_signature(const char* signature) {
3713     const char *p;
3714     for (p = signature; *p != JVM_SIGNATURE_ENDFUNC; p++) {
3715         switch (*p) {
3716           case JVM_SIGNATURE_BOOLEAN:
3717           case JVM_SIGNATURE_BYTE:
3718           case JVM_SIGNATURE_CHAR:
3719           case JVM_SIGNATURE_SHORT:
3720           case JVM_SIGNATURE_INT:
3721           case JVM_SIGNATURE_FLOAT:
3722           case JVM_SIGNATURE_DOUBLE:
3723           case JVM_SIGNATURE_LONG:
3724           case JVM_SIGNATURE_FUNC:  /* ignore initial (, if given */
3725             break;
3726           case JVM_SIGNATURE_CLASS:

3727             while (*p != JVM_SIGNATURE_ENDCLASS) p++;
3728             break;
3729           case JVM_SIGNATURE_ARRAY:
3730             while (*p == JVM_SIGNATURE_ARRAY) p++;
3731             /* If an array of classes, skip over class name, too. */
3732             if (*p == JVM_SIGNATURE_CLASS) {
3733                 while (*p != JVM_SIGNATURE_ENDCLASS) p++;
3734             }
3735             break;
3736           default:
3737             /* Indicate an error. */
3738             return NULL;
3739         }
3740     }
3741     return p++; /* skip over ')'. */
3742 }
3743 
3744 static char
3745 signature_to_fieldtype(context_type *context,
3746                        const char **signature_p, fullinfo_type *full_info_p)
3747 {
3748     const char *p = *signature_p;
3749     fullinfo_type full_info = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
3750     char result;
3751     int array_depth = 0;
3752 

3791 
3792             case JVM_SIGNATURE_FLOAT:
3793                 full_info = MAKE_FULLINFO(ITEM_Float, 0, 0);
3794                 result = 'F';
3795                 break;
3796 
3797             case JVM_SIGNATURE_DOUBLE:
3798                 full_info = MAKE_FULLINFO(ITEM_Double, 0, 0);
3799                 result = 'D';
3800                 break;
3801 
3802             case JVM_SIGNATURE_LONG:
3803                 full_info = MAKE_FULLINFO(ITEM_Long, 0, 0);
3804                 result = 'L';
3805                 break;
3806 
3807             case JVM_SIGNATURE_ARRAY:
3808                 array_depth++;
3809                 continue;       /* only time we ever do the loop > 1 */
3810 
3811             case JVM_SIGNATURE_CLASS: {

3812                 char buffer_space[256];
3813                 char *buffer = buffer_space;
3814                 char *finish = strchr(p, JVM_SIGNATURE_ENDCLASS);
3815                 int length;
3816                 if (finish == NULL) {
3817                     /* Signature must have ';' after the class name.
3818                      * If it does not, return 0 and ITEM_Bogus in full_info. */
3819                     result = 0;
3820                     break;
3821                 }
3822                 assert(finish >= p);
3823                 length = (int)(finish - p);
3824                 if (length + 1 > (int)sizeof(buffer_space)) {
3825                     buffer = calloc(length + 1, sizeof(char));
3826                     check_and_push(context, buffer, VM_MALLOC_BLK);
3827                 }
3828                 memcpy(buffer, p, length);
3829                 buffer[length] = '\0';
3830                 full_info = make_class_info_from_name(context, buffer);
3831                 result = 'A';

4174         context->alloc_stack_top--;
4175     else
4176         free(p);
4177 }
4178 
4179 static int signature_to_args_size(const char *method_signature)
4180 {
4181     const char *p;
4182     int args_size = 0;
4183     for (p = method_signature; *p != JVM_SIGNATURE_ENDFUNC; p++) {
4184         switch (*p) {
4185           case JVM_SIGNATURE_BOOLEAN:
4186           case JVM_SIGNATURE_BYTE:
4187           case JVM_SIGNATURE_CHAR:
4188           case JVM_SIGNATURE_SHORT:
4189           case JVM_SIGNATURE_INT:
4190           case JVM_SIGNATURE_FLOAT:
4191             args_size += 1;
4192             break;
4193           case JVM_SIGNATURE_CLASS:

4194             args_size += 1;
4195             while (*p != JVM_SIGNATURE_ENDCLASS) p++;
4196             break;
4197           case JVM_SIGNATURE_ARRAY:
4198             args_size += 1;
4199             while ((*p == JVM_SIGNATURE_ARRAY)) p++;
4200             /* If an array of classes, skip over class name, too. */
4201             if (*p == JVM_SIGNATURE_CLASS) {
4202                 while (*p != JVM_SIGNATURE_ENDCLASS)
4203                   p++;
4204             }
4205             break;
4206           case JVM_SIGNATURE_DOUBLE:
4207           case JVM_SIGNATURE_LONG:
4208             args_size += 2;
4209             break;
4210           case JVM_SIGNATURE_FUNC:  /* ignore initial (, if given */
4211             break;
4212           default:
4213             /* Indicate an error. */
4214             return 0;
4215         }
4216     }
4217     return args_size;
4218 }
4219 
4220 #ifdef DEBUG
4221 

3707 
3708 /*
3709  * Need to scan the entire signature to find the result type because
3710  * types in the arg list and the result type could contain embedded ')'s.
3711  */
3712 static const char* get_result_signature(const char* signature) {
3713     const char *p;
3714     for (p = signature; *p != JVM_SIGNATURE_ENDFUNC; p++) {
3715         switch (*p) {
3716           case JVM_SIGNATURE_BOOLEAN:
3717           case JVM_SIGNATURE_BYTE:
3718           case JVM_SIGNATURE_CHAR:
3719           case JVM_SIGNATURE_SHORT:
3720           case JVM_SIGNATURE_INT:
3721           case JVM_SIGNATURE_FLOAT:
3722           case JVM_SIGNATURE_DOUBLE:
3723           case JVM_SIGNATURE_LONG:
3724           case JVM_SIGNATURE_FUNC:  /* ignore initial (, if given */
3725             break;
3726           case JVM_SIGNATURE_CLASS:
3727           case JVM_SIGNATURE_INLINE_TYPE:
3728             while (*p != JVM_SIGNATURE_ENDCLASS) p++;
3729             break;
3730           case JVM_SIGNATURE_ARRAY:
3731             while (*p == JVM_SIGNATURE_ARRAY) p++;
3732             /* If an array of classes, skip over class name, too. */
3733             if (*p == JVM_SIGNATURE_CLASS || *p == JVM_SIGNATURE_INLINE_TYPE) {
3734                 while (*p != JVM_SIGNATURE_ENDCLASS) p++;
3735             }
3736             break;
3737           default:
3738             /* Indicate an error. */
3739             return NULL;
3740         }
3741     }
3742     return p++; /* skip over ')'. */
3743 }
3744 
3745 static char
3746 signature_to_fieldtype(context_type *context,
3747                        const char **signature_p, fullinfo_type *full_info_p)
3748 {
3749     const char *p = *signature_p;
3750     fullinfo_type full_info = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
3751     char result;
3752     int array_depth = 0;
3753 

3792 
3793             case JVM_SIGNATURE_FLOAT:
3794                 full_info = MAKE_FULLINFO(ITEM_Float, 0, 0);
3795                 result = 'F';
3796                 break;
3797 
3798             case JVM_SIGNATURE_DOUBLE:
3799                 full_info = MAKE_FULLINFO(ITEM_Double, 0, 0);
3800                 result = 'D';
3801                 break;
3802 
3803             case JVM_SIGNATURE_LONG:
3804                 full_info = MAKE_FULLINFO(ITEM_Long, 0, 0);
3805                 result = 'L';
3806                 break;
3807 
3808             case JVM_SIGNATURE_ARRAY:
3809                 array_depth++;
3810                 continue;       /* only time we ever do the loop > 1 */
3811 
3812             case JVM_SIGNATURE_CLASS:
3813             case JVM_SIGNATURE_INLINE_TYPE: {
3814                 char buffer_space[256];
3815                 char *buffer = buffer_space;
3816                 char *finish = strchr(p, JVM_SIGNATURE_ENDCLASS);
3817                 int length;
3818                 if (finish == NULL) {
3819                     /* Signature must have ';' after the class name.
3820                      * If it does not, return 0 and ITEM_Bogus in full_info. */
3821                     result = 0;
3822                     break;
3823                 }
3824                 assert(finish >= p);
3825                 length = (int)(finish - p);
3826                 if (length + 1 > (int)sizeof(buffer_space)) {
3827                     buffer = calloc(length + 1, sizeof(char));
3828                     check_and_push(context, buffer, VM_MALLOC_BLK);
3829                 }
3830                 memcpy(buffer, p, length);
3831                 buffer[length] = '\0';
3832                 full_info = make_class_info_from_name(context, buffer);
3833                 result = 'A';

4176         context->alloc_stack_top--;
4177     else
4178         free(p);
4179 }
4180 
4181 static int signature_to_args_size(const char *method_signature)
4182 {
4183     const char *p;
4184     int args_size = 0;
4185     for (p = method_signature; *p != JVM_SIGNATURE_ENDFUNC; p++) {
4186         switch (*p) {
4187           case JVM_SIGNATURE_BOOLEAN:
4188           case JVM_SIGNATURE_BYTE:
4189           case JVM_SIGNATURE_CHAR:
4190           case JVM_SIGNATURE_SHORT:
4191           case JVM_SIGNATURE_INT:
4192           case JVM_SIGNATURE_FLOAT:
4193             args_size += 1;
4194             break;
4195           case JVM_SIGNATURE_CLASS:
4196           case JVM_SIGNATURE_INLINE_TYPE:
4197             args_size += 1;
4198             while (*p != JVM_SIGNATURE_ENDCLASS) p++;
4199             break;
4200           case JVM_SIGNATURE_ARRAY:
4201             args_size += 1;
4202             while ((*p == JVM_SIGNATURE_ARRAY)) p++;
4203             /* If an array of classes, skip over class name, too. */
4204             if (*p == JVM_SIGNATURE_CLASS || *p == JVM_SIGNATURE_INLINE_TYPE) {
4205                 while (*p != JVM_SIGNATURE_ENDCLASS)
4206                   p++;
4207             }
4208             break;
4209           case JVM_SIGNATURE_DOUBLE:
4210           case JVM_SIGNATURE_LONG:
4211             args_size += 2;
4212             break;
4213           case JVM_SIGNATURE_FUNC:  /* ignore initial (, if given */
4214             break;
4215           default:
4216             /* Indicate an error. */
4217             return 0;
4218         }
4219     }
4220     return args_size;
4221 }
4222 
4223 #ifdef DEBUG
4224 
< prev index next >