duke@435: /* jiangli@3701: * Copyright (c) 1997, 2012, 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/javaClasses.hpp" stefank@2314: #include "classfile/symbolTable.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/instanceKlass.hpp" stefank@2314: #include "oops/instanceOop.hpp" stefank@2314: #include "oops/objArrayOop.hpp" stefank@2314: #include "oops/oop.inline.hpp" duke@435: duke@435: duke@435: typeArrayOop oopFactory::new_charArray(const char* utf8_str, TRAPS) { duke@435: int length = utf8_str == NULL ? 0 : UTF8::unicode_length(utf8_str); duke@435: typeArrayOop result = new_charArray(length, CHECK_NULL); duke@435: if (length > 0) { duke@435: UTF8::convert_to_unicode(utf8_str, result->char_at_addr(0), length); duke@435: } duke@435: return result; duke@435: } duke@435: coleenp@4037: typeArrayOop oopFactory::new_tenured_charArray(int length, TRAPS) { coleenp@4142: return TypeArrayKlass::cast(Universe::charArrayKlassObj())->allocate(length, THREAD); duke@435: } duke@435: coleenp@4037: typeArrayOop oopFactory::new_typeArray(BasicType type, int length, TRAPS) { coleenp@4037: Klass* type_asKlassOop = Universe::typeArrayKlassObj(type); coleenp@4142: TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop); coleenp@4037: typeArrayOop result = type_asArrayKlass->allocate(length, THREAD); coleenp@4037: return result; duke@435: } duke@435: coleenp@4037: // Create a Java array that points to metadata. coleenp@4037: // As far as Java code is concerned, a metaData array is either an array of coleenp@4037: // int or long depending on pointer size. Only a few things use this, like coleenp@4037: // stack trace elements in Throwable. They cast Method* into this type. coleenp@4037: // Note:can't point to symbols because there's no way to unreference count coleenp@4037: // them when this object goes away. coleenp@4037: typeArrayOop oopFactory::new_metaDataArray(int length, TRAPS) { coleenp@4037: BasicType type = LP64_ONLY(T_LONG) NOT_LP64(T_INT); coleenp@4037: Klass* type_asKlassOop = Universe::typeArrayKlassObj(type); coleenp@4142: TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop); kvn@3157: typeArrayOop result = type_asArrayKlass->allocate_common(length, true, THREAD); kvn@3157: return result; kvn@3157: } kvn@3157: kvn@3157: typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) { coleenp@4037: Klass* type_asKlassOop = Universe::typeArrayKlassObj(type); coleenp@4142: TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop); kvn@3157: typeArrayOop result = type_asArrayKlass->allocate_common(length, false, THREAD); duke@435: return result; duke@435: } duke@435: duke@435: coleenp@4037: objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) { duke@435: assert(klass->is_klass(), "must be instance class"); coleenp@4037: if (klass->oop_is_array()) { coleenp@4142: return ((ArrayKlass*)klass)->allocate_arrayArray(1, length, THREAD); duke@435: } else { coleenp@4037: assert (klass->oop_is_instance(), "new object array with klass not an InstanceKlass"); coleenp@4037: return ((InstanceKlass*)klass)->allocate_objArray(1, length, THREAD); duke@435: } duke@435: }