byteArrayKlass.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.31 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 # include "incls/_precompiled.incl"
00025 # include "incls/_byteArrayKlass.cpp.incl"
00026 # include <ctype.h>
00027 
00028 oop byteArrayKlass::allocateObject() {
00029   assert(!can_inline_allocation(), "using nonstandard allocation");
00030   fatal("should never call allocateObject in byteArrayKlass");
00031   return badOop;
00032 }
00033 
00034 oop byteArrayKlass::allocateObjectSize(int size) {
00035   klassOop k        = as_klassOop();
00036   int      ni_size  = non_indexable_size();
00037   int      obj_size = ni_size + 1 + roundTo(size, oopSize) / oopSize;
00038   // allocate
00039   byteArrayOop obj = as_byteArrayOop(Universe::allocate(obj_size, (memOop*)&k));
00040   // header
00041   memOop(obj)->initialize_header(true, k);
00042   // instance variables
00043   memOop(obj)->initialize_body(memOopDesc::header_size(), ni_size);
00044   // indexables
00045   oop* base = (oop*) obj->addr();
00046   oop* end  = base + obj_size;
00047   // %optimized 'obj->set_length(size)'
00048   base[ni_size] = as_smiOop(size);
00049   // %optimized 'for (int index = 1; index <= size; index++)
00050   //               obj->byte_at_put(index, '\000')'
00051   base = &base[ni_size+1];
00052   while (base < end) *base++ = (oop) 0;
00053   return obj;
00054 }
00055 
00056 klassOop byteArrayKlass::create_subclass(mixinOop mixin, Format format) {
00057   if (format == mem_klass || format == byteArray_klass) {
00058     return byteArrayKlass::create_class(as_klassOop(), mixin);
00059   }
00060   return NULL;
00061 }
00062 
00063 klassOop byteArrayKlass::create_class(klassOop super_class, mixinOop mixin) {
00064   byteArrayKlass o;
00065   return create_generic_class(super_class, mixin, o.vtbl_value());
00066 }
00067 
00068 void byteArrayKlass::initialize_object(byteArrayOop obj, char* value, int len){
00069   for (int index = 1; index <= len; index++) {
00070     obj->byte_at_put(index, value[index-1]);
00071   }
00072 }
00073 
00074 void set_byteArrayKlass_vtbl(Klass* k) {
00075   byteArrayKlass o;
00076   k->set_vtbl_value(o.vtbl_value());
00077 }
00078 
00079 bool byteArrayKlass::oop_verify(oop obj) {
00080   assert_byteArray(obj,"Argument must be byteArray");
00081   return byteArrayOop(obj)->verify();
00082 }
00083 
00084 void byteArrayKlass::oop_print_value_on(oop obj, outputStream* st) {
00085   assert_byteArray(obj,"Argument must be byteArray");
00086   byteArrayOop array = byteArrayOop(obj);
00087   int len = array->length();
00088   int n   = min(MaxElementPrintSize, len);
00089   st->print("'");
00090   for(int index = 1; index <= n; index++) {
00091     char c = array->byte_at(index);
00092     if (isprint(c)) st->print("%c",   c);
00093     else            st->print("\\%o", c);
00094   }
00095   if (n < len) st->print("...");
00096   st->print("'");
00097 }
00098 
00099 void byteArrayKlass::oop_layout_iterate(oop obj, ObjectLayoutClosure* blk) {
00100   u_char* p   = byteArrayOop(obj)->bytes();
00101   oop*  l   = byteArrayOop(obj)->length_addr();
00102   int   len = byteArrayOop(obj)->length();
00103   // header + instance variables
00104   memOopKlass::oop_layout_iterate(obj, blk);
00105   // indexables
00106   blk->begin_indexables();
00107   blk->do_oop("length", l);
00108   for (int index = 1; index <= len; index++) {
00109     blk->do_indexable_byte(index, p++);
00110   }
00111   blk->end_indexables();
00112 }
00113 
00114 void byteArrayKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
00115   oop* l = byteArrayOop(obj)->length_addr();
00116   // header + instance variables
00117   memOopKlass::oop_oop_iterate(obj, blk);
00118   blk->do_oop(l);
00119 }
00120 
00121 int byteArrayKlass::oop_scavenge_contents(oop obj) {
00122   // header + instance variables
00123   memOopKlass::oop_scavenge_contents(obj);
00124   return object_size(byteArrayOop(obj)->length());  
00125 }
00126 
00127 int byteArrayKlass::oop_scavenge_tenured_contents(oop obj) {
00128   // header + instance variables
00129   memOopKlass::oop_scavenge_tenured_contents(obj);
00130   return object_size(byteArrayOop(obj)->length());  
00131 }

Generated on Mon Oct 9 13:37:04 2006 for Strongtalk VM by  doxygen 1.4.7