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