37 } |
37 } |
38 |
38 |
39 // Check if it is a valid array signature |
39 // Check if it is a valid array signature |
40 bool FieldType::is_valid_array_signature(Symbol* sig) { |
40 bool FieldType::is_valid_array_signature(Symbol* sig) { |
41 assert(sig->utf8_length() > 1, "this should already have been checked"); |
41 assert(sig->utf8_length() > 1, "this should already have been checked"); |
42 assert(sig->char_at(0) == '[', "this should already have been checked"); |
42 assert(sig->char_at(0) == JVM_SIGNATURE_ARRAY, "this should already have been checked"); |
43 // The first character is already checked |
43 // The first character is already checked |
44 int i = 1; |
44 int i = 1; |
45 int len = sig->utf8_length(); |
45 int len = sig->utf8_length(); |
46 // First skip all '['s |
46 // First skip all '['s |
47 while(i < len - 1 && sig->char_at(i) == '[') i++; |
47 while(i < len - 1 && sig->char_at(i) == JVM_SIGNATURE_ARRAY) i++; |
48 |
48 |
49 // Check type |
49 // Check type |
50 switch(sig->char_at(i)) { |
50 switch(sig->char_at(i)) { |
51 case 'B': // T_BYTE |
51 case JVM_SIGNATURE_BYTE: |
52 case 'C': // T_CHAR |
52 case JVM_SIGNATURE_CHAR: |
53 case 'D': // T_DOUBLE |
53 case JVM_SIGNATURE_DOUBLE: |
54 case 'F': // T_FLOAT |
54 case JVM_SIGNATURE_FLOAT: |
55 case 'I': // T_INT |
55 case JVM_SIGNATURE_INT: |
56 case 'J': // T_LONG |
56 case JVM_SIGNATURE_LONG: |
57 case 'S': // T_SHORT |
57 case JVM_SIGNATURE_SHORT: |
58 case 'Z': // T_BOOLEAN |
58 case JVM_SIGNATURE_BOOLEAN: |
59 // If it is an array, the type is the last character |
59 // If it is an array, the type is the last character |
60 return (i + 1 == len); |
60 return (i + 1 == len); |
61 case 'L': |
61 case JVM_SIGNATURE_CLASS: |
62 // If it is an object, the last character must be a ';' |
62 // If it is an object, the last character must be a ';' |
63 return sig->char_at(len - 1) == ';'; |
63 return sig->char_at(len - 1) == JVM_SIGNATURE_ENDCLASS; |
64 } |
64 } |
65 |
65 |
66 return false; |
66 return false; |
67 } |
67 } |
68 |
68 |
69 |
69 |
70 BasicType FieldType::get_array_info(Symbol* signature, FieldArrayInfo& fd, TRAPS) { |
70 BasicType FieldType::get_array_info(Symbol* signature, FieldArrayInfo& fd, TRAPS) { |
71 assert(basic_type(signature) == T_ARRAY, "must be array"); |
71 assert(basic_type(signature) == T_ARRAY, "must be array"); |
72 int index = 1; |
72 int index = 1; |
73 int dim = 1; |
73 int dim = 1; |
74 while (signature->char_at(index) == '[') { |
74 while (signature->char_at(index) == JVM_SIGNATURE_ARRAY) { |
75 index++; |
75 index++; |
76 dim++; |
76 dim++; |
77 } |
77 } |
78 ResourceMark rm; |
78 ResourceMark rm; |
79 char *element = signature->as_C_string() + index; |
79 char *element = signature->as_C_string() + index; |
80 BasicType element_type = char2type(element[0]); |
80 BasicType element_type = char2type(element[0]); |
81 if (element_type == T_OBJECT) { |
81 if (element_type == T_OBJECT) { |
82 int len = (int)strlen(element); |
82 int len = (int)strlen(element); |
83 assert(element[len-1] == ';', "last char should be a semicolon"); |
83 assert(element[len-1] == JVM_SIGNATURE_ENDCLASS, "last char should be a semicolon"); |
84 element[len-1] = '\0'; // chop off semicolon |
84 element[len-1] = '\0'; // chop off semicolon |
85 fd._object_key = SymbolTable::new_symbol(element + 1); |
85 fd._object_key = SymbolTable::new_symbol(element + 1); |
86 } |
86 } |
87 // Pass dimension back to caller |
87 // Pass dimension back to caller |
88 fd._dimension = dim; |
88 fd._dimension = dim; |