0N/A/*
3669N/A * Copyright (c) 1997, 2012, 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/javaClasses.hpp"
1879N/A#include "classfile/symbolTable.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "memory/oopFactory.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/compiledICHolderKlass.hpp"
1879N/A#include "oops/constMethodKlass.hpp"
1879N/A#include "oops/constantPoolKlass.hpp"
1879N/A#include "oops/cpCacheKlass.hpp"
1879N/A#include "oops/instanceKlass.hpp"
1879N/A#include "oops/instanceKlassKlass.hpp"
1879N/A#include "oops/instanceOop.hpp"
1879N/A#include "oops/klassKlass.hpp"
1879N/A#include "oops/klassOop.hpp"
1879N/A#include "oops/methodDataKlass.hpp"
1879N/A#include "oops/methodKlass.hpp"
1879N/A#include "oops/objArrayOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
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);
2797N/A typeArrayOop result = type_asArrayKlass->allocate_common(length, true, THREAD);
2797N/A return result;
2797N/A}
2797N/A
2797N/AtypeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) {
2797N/A klassOop type_asKlassOop = Universe::typeArrayKlassObj(type);
2797N/A typeArrayKlass* type_asArrayKlass = typeArrayKlass::cast(type_asKlassOop);
2797N/A typeArrayOop result = type_asArrayKlass->allocate_common(length, false, 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
2139N/AobjArrayOop oopFactory::new_system_objArray(int length, TRAPS) {
0N/A int size = objArrayOopDesc::object_size(length);
0N/A KlassHandle klass (THREAD, Universe::systemObjArrayKlassObj());
2139N/A objArrayOop o = (objArrayOop)
2139N/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
518N/AconstantPoolOop oopFactory::new_constantPool(int length,
518N/A bool is_conc_safe,
518N/A TRAPS) {
0N/A constantPoolKlass* ck = constantPoolKlass::cast(Universe::constantPoolKlassObj());
518N/A return ck->allocate(length, is_conc_safe, CHECK_NULL);
0N/A}
0N/A
0N/A
542N/AconstantPoolCacheOop oopFactory::new_constantPoolCache(int length,
542N/A TRAPS) {
0N/A constantPoolCacheKlass* ck = constantPoolCacheKlass::cast(Universe::constantPoolCacheKlassObj());
2098N/A return ck->allocate(length, CHECK_NULL);
0N/A}
0N/A
0N/A
2223N/AklassOop oopFactory::new_instanceKlass(Symbol* name, int vtable_len, int itable_len,
939N/A int static_field_size,
939N/A unsigned int nonstatic_oop_map_count,
3669N/A AccessFlags access_flags,
3707N/A ReferenceType rt,
3707N/A KlassHandle host_klass, TRAPS) {
0N/A instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj());
3669N/A return ikk->allocate_instance_klass(name, vtable_len, itable_len,
3669N/A static_field_size, nonstatic_oop_map_count,
3707N/A access_flags, rt, host_klass, 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,
3879N/A int exception_table_length,
0N/A int checked_exceptions_length,
518N/A bool is_conc_safe,
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,
3879N/A localvariable_table_length, exception_table_length,
3879N/A checked_exceptions_length, is_conc_safe,
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,
3879N/A int exception_table_length,
518N/A int checked_exceptions_length,
518N/A bool is_conc_safe,
518N/A 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,
3879N/A exception_table_length,
518N/A checked_exceptions_length,
518N/A is_conc_safe, 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}