dValueArray_prims.cpp

Go to the documentation of this file.
00001 /* Copyright 1996 LongView Technologies L.L.C. $Revision: 1.2 $ */
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/_dValueArray_prims.cpp.incl"
00026 
00027 TRACE_FUNC(TraceDoubleValueArrayPrims, "doubleValueArray")
00028 
00029 int doubleValueArrayPrimitives::number_of_calls;
00030 
00031 #define ASSERT_RECEIVER assert(receiver->is_doubleValueArray(), "receiver must be double value array")
00032 
00033 PRIM_DECL_2(doubleValueArrayPrimitives::allocateSize, oop receiver, oop argument) {
00034   PROLOGUE_2("allocateSize", receiver, argument)
00035   assert(receiver->is_klass() && klassOop(receiver)->klass_part()->oop_is_doubleValueArray(),
00036          "receiver must double byte array class");
00037   if (!argument->is_smi())
00038     markSymbol(vmSymbols::first_argument_has_wrong_type());
00039 
00040   if (smiOop(argument)->value() < 0)
00041     return markSymbol(vmSymbols::negative_size());
00042 
00043   int length = smiOop(argument)->value();
00044 
00045   klassOop k        = klassOop(receiver);
00046   int      ni_size  = k->klass_part()->non_indexable_size();
00047   int      obj_size = ni_size + 1 + roundTo(length * sizeof(double), oopSize) / oopSize;
00048   // allocate
00049   doubleValueArrayOop obj = as_doubleValueArrayOop(Universe::allocate(obj_size, (memOop*)&k));
00050   // header
00051   memOop(obj)->initialize_header(true, k);
00052   // instance variables
00053   memOop(obj)->initialize_body(memOopDesc::header_size(), ni_size);
00054   obj->set_length(length);
00055   for (int index = 1; index <= length; index++) {
00056     obj->double_at_put(index, 0.0);
00057   }
00058   return obj;
00059 }
00060 
00061 PRIM_DECL_1(doubleValueArrayPrimitives::size, oop receiver) {
00062   PROLOGUE_1("size", receiver);
00063   ASSERT_RECEIVER;
00064 
00065   // do the operation
00066   return as_smiOop(doubleValueArrayOop(receiver)->length());
00067 }
00068 
00069 PRIM_DECL_2(doubleValueArrayPrimitives::at, oop receiver, oop index) {
00070   PROLOGUE_2("at", receiver, index);
00071   ASSERT_RECEIVER;
00072 
00073   // check index type
00074   if (!index->is_smi())
00075     return markSymbol(vmSymbols::first_argument_has_wrong_type());
00076 
00077   // check index value
00078   if (!doubleValueArrayOop(receiver)->is_within_bounds(smiOop(index)->value()))
00079      return markSymbol(vmSymbols::out_of_bounds());
00080 
00081   return oopFactory::new_double(doubleValueArrayOop(receiver)->double_at(smiOop(index)->value()));
00082 }
00083 
00084 PRIM_DECL_3(doubleValueArrayPrimitives::atPut, oop receiver, oop index, oop value) {
00085   PROLOGUE_3("atPut", receiver, index, value);
00086   ASSERT_RECEIVER;
00087 
00088   // check index type
00089   if (!index->is_smi())
00090     return markSymbol(vmSymbols::first_argument_has_wrong_type());
00091 
00092   // check value type
00093   if (!value->is_double())
00094     return markSymbol(vmSymbols::second_argument_has_wrong_type());
00095 
00096   // check index value
00097   if (!doubleValueArrayOop(receiver)->is_within_bounds(smiOop(index)->value()))
00098      return markSymbol(vmSymbols::out_of_bounds());
00099 
00100   // do the operation
00101   doubleValueArrayOop(receiver)->double_at_put(smiOop(index)->value(), doubleOop(value)->value());
00102   return receiver;
00103 }
00104 

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