oopFactory.cpp revision 0
0N/A/*
0N/A * Copyright 1997-2007 Sun Microsystems, Inc. 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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A# include "incls/_precompiled.incl"
0N/A# include "incls/_oopFactory.cpp.incl"
0N/A
0N/A
0N/AtypeArrayOop oopFactory::new_charArray(const char* utf8_str, TRAPS) {
0N/A int length = utf8_str == NULL ? 0 : UTF8::unicode_length(utf8_str);
0N/A typeArrayOop result = new_charArray(length, CHECK_NULL);
0N/A if (length > 0) {
0N/A UTF8::convert_to_unicode(utf8_str, result->char_at_addr(0), length);
0N/A }
0N/A return result;
0N/A}
0N/A
0N/AtypeArrayOop oopFactory::new_permanent_charArray(int length, TRAPS) {
0N/A return typeArrayKlass::cast(Universe::charArrayKlassObj())->allocate_permanent(length, THREAD);
0N/A}
0N/A
0N/AtypeArrayOop oopFactory::new_permanent_byteArray(int length, TRAPS) {
0N/A return typeArrayKlass::cast(Universe::byteArrayKlassObj())->allocate_permanent(length, THREAD);
0N/A}
0N/A
0N/A
0N/AtypeArrayOop oopFactory::new_permanent_shortArray(int length, TRAPS) {
0N/A return typeArrayKlass::cast(Universe::shortArrayKlassObj())->allocate_permanent(length, THREAD);
0N/A}
0N/A
0N/A
0N/AtypeArrayOop oopFactory::new_permanent_intArray(int length, TRAPS) {
0N/A return typeArrayKlass::cast(Universe::intArrayKlassObj())->allocate_permanent(length, THREAD);
0N/A}
0N/A
0N/A
0N/AtypeArrayOop oopFactory::new_typeArray(BasicType type, int length, TRAPS) {
0N/A klassOop type_asKlassOop = Universe::typeArrayKlassObj(type);
0N/A typeArrayKlass* type_asArrayKlass = typeArrayKlass::cast(type_asKlassOop);
0N/A typeArrayOop result = type_asArrayKlass->allocate(length, THREAD);
0N/A return result;
0N/A}
0N/A
0N/A
0N/AobjArrayOop oopFactory::new_objArray(klassOop klass, int length, TRAPS) {
0N/A assert(klass->is_klass(), "must be instance class");
0N/A if (klass->klass_part()->oop_is_array()) {
0N/A return ((arrayKlass*)klass->klass_part())->allocate_arrayArray(1, length, THREAD);
0N/A } else {
0N/A assert (klass->klass_part()->oop_is_instance(), "new object array with klass not an instanceKlass");
0N/A return ((instanceKlass*)klass->klass_part())->allocate_objArray(1, length, THREAD);
0N/A }
0N/A}
0N/A
0N/AobjArrayOop oopFactory::new_system_objArray(int length, TRAPS) {
0N/A int size = objArrayOopDesc::object_size(length);
0N/A KlassHandle klass (THREAD, Universe::systemObjArrayKlassObj());
0N/A objArrayOop o = (objArrayOop)
0N/A Universe::heap()->permanent_array_allocate(klass, size, length, CHECK_NULL);
0N/A // initialization not needed, allocated cleared
0N/A return o;
0N/A}
0N/A
0N/A
0N/AconstantPoolOop oopFactory::new_constantPool(int length, TRAPS) {
0N/A constantPoolKlass* ck = constantPoolKlass::cast(Universe::constantPoolKlassObj());
0N/A return ck->allocate(length, CHECK_NULL);
0N/A}
0N/A
0N/A
0N/AconstantPoolCacheOop oopFactory::new_constantPoolCache(int length, TRAPS) {
0N/A constantPoolCacheKlass* ck = constantPoolCacheKlass::cast(Universe::constantPoolCacheKlassObj());
0N/A return ck->allocate(length, CHECK_NULL);
0N/A}
0N/A
0N/A
0N/AklassOop oopFactory::new_instanceKlass(int vtable_len, int itable_len, int static_field_size,
0N/A int nonstatic_oop_map_size, ReferenceType rt, TRAPS) {
0N/A instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj());
0N/A return ikk->allocate_instance_klass(vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, CHECK_NULL);
0N/A}
0N/A
0N/A
0N/AconstMethodOop oopFactory::new_constMethod(int byte_code_size,
0N/A int compressed_line_number_size,
0N/A int localvariable_table_length,
0N/A int checked_exceptions_length,
0N/A TRAPS) {
0N/A klassOop cmkObj = Universe::constMethodKlassObj();
0N/A constMethodKlass* cmk = constMethodKlass::cast(cmkObj);
0N/A return cmk->allocate(byte_code_size, compressed_line_number_size,
0N/A localvariable_table_length, checked_exceptions_length,
0N/A CHECK_NULL);
0N/A}
0N/A
0N/A
0N/AmethodOop oopFactory::new_method(int byte_code_size, AccessFlags access_flags,
0N/A int compressed_line_number_size,
0N/A int localvariable_table_length,
0N/A int checked_exceptions_length, TRAPS) {
0N/A methodKlass* mk = methodKlass::cast(Universe::methodKlassObj());
0N/A assert(!access_flags.is_native() || byte_code_size == 0,
0N/A "native methods should not contain byte codes");
0N/A constMethodOop cm = new_constMethod(byte_code_size,
0N/A compressed_line_number_size,
0N/A localvariable_table_length,
0N/A checked_exceptions_length, CHECK_NULL);
0N/A constMethodHandle rw(THREAD, cm);
0N/A return mk->allocate(rw, access_flags, CHECK_NULL);
0N/A}
0N/A
0N/A
0N/AmethodDataOop oopFactory::new_methodData(methodHandle method, TRAPS) {
0N/A methodDataKlass* mdk = methodDataKlass::cast(Universe::methodDataKlassObj());
0N/A return mdk->allocate(method, CHECK_NULL);
0N/A}
0N/A
0N/A
0N/AcompiledICHolderOop oopFactory::new_compiledICHolder(methodHandle method, KlassHandle klass, TRAPS) {
0N/A compiledICHolderKlass* ck = (compiledICHolderKlass*) Universe::compiledICHolderKlassObj()->klass_part();
0N/A compiledICHolderOop c = ck->allocate(CHECK_NULL);
0N/A c->set_holder_method(method());
0N/A c->set_holder_klass(klass());
0N/A return c;
0N/A}