dByteArray_prims.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.18 $ */
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/_dByteArray_prims.cpp.incl"
00026 
00027 TRACE_FUNC(TraceDoubleByteArrayPrims, "doubleByteArray")
00028 
00029 int doubleByteArrayPrimitives::number_of_calls;
00030 
00031 #define ASSERT_RECEIVER assert(receiver->is_doubleByteArray(), "receiver must be double byte array")
00032 
00033 
00034 PRIM_DECL_2(doubleByteArrayPrimitives::allocateSize, oop receiver, oop argument) {
00035   PROLOGUE_2("allocateSize", receiver, argument)
00036   assert(receiver->is_klass() && klassOop(receiver)->klass_part()->oop_is_doubleByteArray(),
00037          "receiver must double byte array class");
00038   if (!argument->is_smi())
00039     markSymbol(vmSymbols::first_argument_has_wrong_type());
00040 
00041   if (smiOop(argument)->value() < 0)
00042     return markSymbol(vmSymbols::negative_size());
00043 
00044   klassOop k        = klassOop(receiver);
00045   int      ni_size  = k->klass_part()->non_indexable_size();
00046   int      obj_size = ni_size + 1 + roundTo(smiOop(argument)->value() * 2, oopSize) / oopSize;
00047   // allocate
00048   doubleByteArrayOop obj = as_doubleByteArrayOop(Universe::allocate(obj_size, (memOop*)&k));
00049   // header
00050   memOop(obj)->initialize_header(true, k);
00051   // instance variables
00052   memOop(obj)->initialize_body(memOopDesc::header_size(), ni_size);
00053   // indexables
00054   oop* base = (oop*) obj->addr();
00055   oop* end  = base + obj_size;
00056   // %optimized 'obj->set_length(size)'
00057   base[ni_size] = argument;
00058   // %optimized 'for (int index = 1; index <= size; index++)
00059   //               obj->doubleByte_at_put(index, 0)'
00060   base = &base[ni_size+1];
00061   while (base < end) *base++ = (oop) 0;
00062   return obj;
00063 }
00064 
00065 PRIM_DECL_1(doubleByteArrayPrimitives::size, oop receiver) {
00066   PROLOGUE_1("size", receiver);
00067   ASSERT_RECEIVER;
00068 
00069   // do the operation
00070   return as_smiOop(doubleByteArrayOop(receiver)->length());
00071 }
00072 
00073 PRIM_DECL_2(doubleByteArrayPrimitives::at, oop receiver, oop index) {
00074   PROLOGUE_2("at", receiver, index);
00075   ASSERT_RECEIVER;
00076 
00077   // check index type
00078   if (!index->is_smi())
00079     return markSymbol(vmSymbols::first_argument_has_wrong_type());
00080 
00081   // check index value
00082   if (!doubleByteArrayOop(receiver)->is_within_bounds(smiOop(index)->value()))
00083      return markSymbol(vmSymbols::out_of_bounds());
00084 
00085   return as_smiOop(doubleByteArrayOop(receiver)->doubleByte_at(smiOop(index)->value()));
00086 }
00087 
00088 PRIM_DECL_3(doubleByteArrayPrimitives::atPut, oop receiver, oop index, oop value) {
00089   PROLOGUE_3("atPut", receiver, index, value);
00090   ASSERT_RECEIVER;
00091 
00092   // check index type
00093   if (!index->is_smi())
00094     return markSymbol(vmSymbols::first_argument_has_wrong_type());
00095 
00096   // check value type
00097   if (!value->is_smi())
00098     return markSymbol(vmSymbols::second_argument_has_wrong_type());
00099 
00100   // check index value
00101   if (!doubleByteArrayOop(receiver)->is_within_bounds(smiOop(index)->value()))
00102      return markSymbol(vmSymbols::out_of_bounds());
00103 
00104   // check value as double byte
00105   unsigned int v = (unsigned int) smiOop(value)->value();
00106   if (v  >= (1<<16))
00107       return markSymbol(vmSymbols::value_out_of_range());
00108 
00109   // do the operation
00110   doubleByteArrayOop(receiver)->doubleByte_at_put(smiOop(index)->value(), v);
00111   return receiver;
00112 }
00113 
00114 
00115 PRIM_DECL_2(doubleByteArrayPrimitives::compare, oop receiver, oop argument) {
00116   PROLOGUE_2("compare", receiver, argument);
00117   ASSERT_RECEIVER;
00118 
00119   if(receiver == argument)
00120     return as_smiOop(0);
00121 
00122   if (argument->is_doubleByteArray())
00123     return as_smiOop(doubleByteArrayOop(receiver)->compare(doubleByteArrayOop(argument)));
00124 
00125   if (argument->is_byteArray())
00126     return as_smiOop(- byteArrayOop(argument)->compare_doubleBytes(doubleByteArrayOop(receiver)));
00127 
00128   return markSymbol(vmSymbols::first_argument_has_wrong_type());
00129 }
00130 
00131 PRIM_DECL_1(doubleByteArrayPrimitives::intern, oop receiver) {
00132   PROLOGUE_1("intern", receiver);
00133   ASSERT_RECEIVER;
00134 
00135   ResourceMark rm;
00136   int   len    = doubleByteArrayOop(receiver)->length();
00137   char* buffer = NEW_RESOURCE_ARRAY(char, len);
00138 
00139   for (int i = 0; i < len; i++) {
00140     int c = doubleByteArrayOop(receiver)->doubleByte_at(i + 1);
00141     if (c >= (1<<8)) {
00142       return markSymbol(vmSymbols::value_out_of_range());
00143     }
00144     buffer[i] = c;
00145   }
00146   symbolOop sym = Universe::symbol_table->lookup(buffer, len);
00147   return sym;
00148 }
00149 
00150 PRIM_DECL_2(doubleByteArrayPrimitives::characterAt, oop receiver, oop index) {
00151   PROLOGUE_2("characterAt", receiver, index);
00152   ASSERT_RECEIVER;
00153 
00154   // check index type
00155   if (!index->is_smi()) 
00156     return markSymbol(vmSymbols::first_argument_has_wrong_type());
00157 
00158   // range check
00159   if (!doubleByteArrayOop(receiver)->is_within_bounds(smiOop(index)->value()))
00160     return markSymbol(vmSymbols::out_of_bounds());
00161 
00162   // fetch double byte
00163   doubleByte byte = doubleByteArrayOop(receiver)->doubleByte_at(smiOop(index)->value());
00164  
00165   if (byte < 256) {
00166     // return the byte+1'th element in asciiCharacter
00167     return Universe::asciiCharacters()->obj_at(byte+1);
00168   } else return markSymbol(vmSymbols::out_of_bounds());
00169 }
00170 
00171 
00172 PRIM_DECL_1(doubleByteArrayPrimitives::hash, oop receiver) {
00173   PROLOGUE_1("intern", receiver);
00174   ASSERT_RECEIVER;
00175   return as_smiOop(doubleByteArrayOop(receiver)->hash_value());
00176 }

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