util.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.21 $ */
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 
00025 # include "incls/_precompiled.incl"
00026 # include "incls/_util.cpp.incl"
00027 # include <string.h>
00028 
00029 int Indent = 0;
00030 
00031 void printIndent() {
00032   for (int i = 0; i < Indent; i++) lprintf("  ");
00033 }
00034 
00035 
00036 # define LOOP_UNROLL(count, body)                                             \
00037     {                                                                         \
00038     assert(count >= 0, "cannot have negative count in loop unroll");          \
00039     int __c1__ = count;                                                      \
00040     for (int __c__ = __c1__ >> 3; __c__; __c__ --) {                         \
00041     body;       body;                                                         \
00042     body;       body;                                                         \
00043     body;       body;                                                         \
00044     body;       body;                                                         \
00045   }                                                                           \
00046     switch (maskBits(__c1__, nthMask(3))) {                                   \
00047    case 7:      body;                                                         \
00048    case 6:      body;                                                         \
00049    case 5:      body;                                                         \
00050    case 4:      body;                                                         \
00051    case 3:      body;                                                         \
00052    case 2:      body;                                                         \
00053    case 1:      body;                                                         \
00054    case 0:      ;                                                             \
00055   } }
00056 
00057 # define DO_UP(from) LOOP_UNROLL(count, *to++ = from)
00058 # define DO_DOWN(from) LOOP_UNROLL(count, *--to = from)
00059 
00060 /*
00061 void copy_oops_up(oop* from, oop* to, int count) {
00062   assert(maskBits(int(from), Tag_Size) == 0, "not word aligned");
00063   assert(maskBits(int(to), Tag_Size) == 0, "not word aligned");
00064   assert(count >= 0, "negative count");
00065 
00066   // block_step was determined by profiling the scavenger.
00067   //  11/14-95 (Robert and Lars)
00068   const int block_step = 4;
00069   
00070   while (count >= block_step) {
00071     *(to+0) = *(from+0);
00072     *(to+1) = *(from+1);
00073     *(to+2) = *(from+2);
00074     *(to+3) = *(from+3);
00075     to    += block_step;
00076     from  += block_step;
00077     count -= block_step;
00078   }
00079 
00080   if (count > 0) {
00081     *(to+0) = *(from+0);
00082     if (count > 1) {
00083       *(to+1) = *(from+1);
00084       if (count > 2) {
00085         *(to+2) = *(from+2);
00086       }
00087     }
00088   }
00089 }
00090 */
00091 void copy_oops_down(oop* from, oop* to, int count) {
00092   assert(maskBits(int(from), Tag_Size) == 0, "not word aligned");
00093   assert(maskBits(int(to), Tag_Size) == 0, "not word aligned");
00094   assert(count >= 0, "negative count");
00095   DO_DOWN(*--from)
00096   }
00097 
00098 /*
00099 void set_oops(oop* to, int count, oop value) {
00100   assert(maskBits(int(to), Tag_Size) == 0, "not word aligned");
00101   assert(count >= 0, "negative count");
00102 
00103   const int block_step = 4;
00104   
00105   while (count >= block_step) {
00106     *(to+0) = value;
00107     *(to+1) = value;
00108     *(to+2) = value;
00109     *(to+3) = value;
00110     to    += block_step;
00111     count -= block_step;
00112   }
00113 
00114   if (count > 0) {
00115     *(to+0) = value;
00116     if (count > 1) {
00117       *(to+1) = value;
00118       if (count > 2) {
00119         *(to+2) = value;
00120       }
00121     }
00122   }
00123 }
00124 */
00125 char* copy_string(char* s) {
00126   int len = strlen(s) + 1;
00127   char* str = NEW_RESOURCE_ARRAY( char, len);
00128   strcpy(str, s);
00129   return str;
00130 }
00131 
00132 char* copy_c_heap_string(char* s) {
00133   int len = strlen(s) + 1;
00134   char* str = NEW_C_HEAP_ARRAY( char, len);
00135   strcpy(str, s);
00136   return str;
00137 }
00138 
00139 char* copy_string(char* s, smi len) {
00140   char* str = NEW_RESOURCE_ARRAY( char, len+1);
00141   memcpy(str, s, len+1);
00142   str[len] = '\0';
00143   return str;
00144 }
00145 
00146 oop catchThisOne;
00147 
00148 void breakpoint() {
00149   flush_logFile();
00150   os::breakpoint();
00151 }
00152 
00153 void error_breakpoint() {
00154   breakpoint();
00155 }

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