duke@435: /* trims@1907: * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: # include "incls/_precompiled.incl" duke@435: # include "incls/_fieldType.cpp.incl" duke@435: duke@435: void FieldType::skip_optional_size(symbolOop signature, int* index) { duke@435: jchar c = signature->byte_at(*index); duke@435: while (c >= '0' && c <= '9') { duke@435: *index = *index + 1; duke@435: c = signature->byte_at(*index); duke@435: } duke@435: } duke@435: duke@435: BasicType FieldType::basic_type(symbolOop signature) { duke@435: return char2type(signature->byte_at(0)); duke@435: } duke@435: duke@435: // Check if it is a valid array signature duke@435: bool FieldType::is_valid_array_signature(symbolOop sig) { duke@435: assert(sig->utf8_length() > 1, "this should already have been checked"); duke@435: assert(sig->byte_at(0) == '[', "this should already have been checked"); duke@435: // The first character is already checked duke@435: int i = 1; duke@435: int len = sig->utf8_length(); duke@435: // First skip all '['s duke@435: while(i < len - 1 && sig->byte_at(i) == '[') i++; duke@435: duke@435: // Check type duke@435: switch(sig->byte_at(i)) { duke@435: case 'B': // T_BYTE duke@435: case 'C': // T_CHAR duke@435: case 'D': // T_DOUBLE duke@435: case 'F': // T_FLOAT duke@435: case 'I': // T_INT duke@435: case 'J': // T_LONG duke@435: case 'S': // T_SHORT duke@435: case 'Z': // T_BOOLEAN duke@435: // If it is an array, the type is the last character duke@435: return (i + 1 == len); duke@435: case 'L': duke@435: // If it is an object, the last character must be a ';' duke@435: return sig->byte_at(len - 1) == ';'; duke@435: } duke@435: duke@435: return false; duke@435: } duke@435: duke@435: duke@435: BasicType FieldType::get_array_info(symbolOop signature, jint* dimension, symbolOop* object_key, TRAPS) { duke@435: assert(basic_type(signature) == T_ARRAY, "must be array"); duke@435: int index = 1; duke@435: int dim = 1; duke@435: skip_optional_size(signature, &index); duke@435: while (signature->byte_at(index) == '[') { duke@435: index++; duke@435: dim++; duke@435: skip_optional_size(signature, &index); duke@435: } duke@435: ResourceMark rm; duke@435: symbolOop element = oopFactory::new_symbol(signature->as_C_string() + index, CHECK_(T_BYTE)); duke@435: BasicType element_type = FieldType::basic_type(element); duke@435: if (element_type == T_OBJECT) { duke@435: char* object_type = element->as_C_string(); duke@435: object_type[element->utf8_length() - 1] = '\0'; duke@435: *object_key = oopFactory::new_symbol(object_type + 1, CHECK_(T_BYTE)); duke@435: } duke@435: // Pass dimension back to caller duke@435: *dimension = dim; duke@435: return element_type; duke@435: }