Fri, 05 Sep 2014 12:36:37 -0700
8057623: add an extension class for argument handling
Reviewed-by: brutisso, mgerdin, tschatzl
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "memory/oopFactory.hpp" |
stefank@2314 | 28 | #include "oops/oop.inline.hpp" |
stefank@2314 | 29 | #include "oops/typeArrayKlass.hpp" |
stefank@2314 | 30 | #include "runtime/fieldType.hpp" |
stefank@2314 | 31 | #include "runtime/signature.hpp" |
duke@435 | 32 | |
coleenp@2497 | 33 | void FieldType::skip_optional_size(Symbol* signature, int* index) { |
duke@435 | 34 | jchar c = signature->byte_at(*index); |
duke@435 | 35 | while (c >= '0' && c <= '9') { |
duke@435 | 36 | *index = *index + 1; |
duke@435 | 37 | c = signature->byte_at(*index); |
duke@435 | 38 | } |
duke@435 | 39 | } |
duke@435 | 40 | |
coleenp@2497 | 41 | BasicType FieldType::basic_type(Symbol* signature) { |
duke@435 | 42 | return char2type(signature->byte_at(0)); |
duke@435 | 43 | } |
duke@435 | 44 | |
duke@435 | 45 | // Check if it is a valid array signature |
coleenp@2497 | 46 | bool FieldType::is_valid_array_signature(Symbol* sig) { |
duke@435 | 47 | assert(sig->utf8_length() > 1, "this should already have been checked"); |
duke@435 | 48 | assert(sig->byte_at(0) == '[', "this should already have been checked"); |
duke@435 | 49 | // The first character is already checked |
duke@435 | 50 | int i = 1; |
duke@435 | 51 | int len = sig->utf8_length(); |
duke@435 | 52 | // First skip all '['s |
duke@435 | 53 | while(i < len - 1 && sig->byte_at(i) == '[') i++; |
duke@435 | 54 | |
duke@435 | 55 | // Check type |
duke@435 | 56 | switch(sig->byte_at(i)) { |
duke@435 | 57 | case 'B': // T_BYTE |
duke@435 | 58 | case 'C': // T_CHAR |
duke@435 | 59 | case 'D': // T_DOUBLE |
duke@435 | 60 | case 'F': // T_FLOAT |
duke@435 | 61 | case 'I': // T_INT |
duke@435 | 62 | case 'J': // T_LONG |
duke@435 | 63 | case 'S': // T_SHORT |
duke@435 | 64 | case 'Z': // T_BOOLEAN |
duke@435 | 65 | // If it is an array, the type is the last character |
duke@435 | 66 | return (i + 1 == len); |
duke@435 | 67 | case 'L': |
duke@435 | 68 | // If it is an object, the last character must be a ';' |
duke@435 | 69 | return sig->byte_at(len - 1) == ';'; |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | return false; |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | |
coleenp@2497 | 76 | BasicType FieldType::get_array_info(Symbol* signature, FieldArrayInfo& fd, TRAPS) { |
duke@435 | 77 | assert(basic_type(signature) == T_ARRAY, "must be array"); |
duke@435 | 78 | int index = 1; |
duke@435 | 79 | int dim = 1; |
duke@435 | 80 | skip_optional_size(signature, &index); |
duke@435 | 81 | while (signature->byte_at(index) == '[') { |
duke@435 | 82 | index++; |
duke@435 | 83 | dim++; |
duke@435 | 84 | skip_optional_size(signature, &index); |
duke@435 | 85 | } |
duke@435 | 86 | ResourceMark rm; |
coleenp@2497 | 87 | char *element = signature->as_C_string() + index; |
coleenp@2497 | 88 | BasicType element_type = char2type(element[0]); |
duke@435 | 89 | if (element_type == T_OBJECT) { |
coleenp@2497 | 90 | int len = (int)strlen(element); |
coleenp@2497 | 91 | assert(element[len-1] == ';', "last char should be a semicolon"); |
coleenp@2497 | 92 | element[len-1] = '\0'; // chop off semicolon |
coleenp@2497 | 93 | fd._object_key = SymbolTable::new_symbol(element + 1, CHECK_(T_BYTE)); |
duke@435 | 94 | } |
duke@435 | 95 | // Pass dimension back to caller |
coleenp@2497 | 96 | fd._dimension = dim; |
duke@435 | 97 | return element_type; |
duke@435 | 98 | } |