duke@435: /* trims@2708: * Copyright (c) 1997, 2011, 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: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/typeArrayKlass.hpp" stefank@2314: #include "runtime/fieldType.hpp" stefank@2314: #include "runtime/signature.hpp" duke@435: coleenp@2497: void FieldType::skip_optional_size(Symbol* 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: coleenp@2497: BasicType FieldType::basic_type(Symbol* signature) { duke@435: return char2type(signature->byte_at(0)); duke@435: } duke@435: duke@435: // Check if it is a valid array signature coleenp@2497: bool FieldType::is_valid_array_signature(Symbol* 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: coleenp@2497: BasicType FieldType::get_array_info(Symbol* signature, FieldArrayInfo& fd, 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; coleenp@2497: char *element = signature->as_C_string() + index; coleenp@2497: BasicType element_type = char2type(element[0]); duke@435: if (element_type == T_OBJECT) { coleenp@2497: int len = (int)strlen(element); coleenp@2497: assert(element[len-1] == ';', "last char should be a semicolon"); coleenp@2497: element[len-1] = '\0'; // chop off semicolon coleenp@2497: fd._object_key = SymbolTable::new_symbol(element + 1, CHECK_(T_BYTE)); duke@435: } duke@435: // Pass dimension back to caller coleenp@2497: fd._dimension = dim; duke@435: return element_type; duke@435: }