src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp

Thu, 26 Mar 2009 14:31:45 -0700

author
never
date
Thu, 26 Mar 2009 14:31:45 -0700
changeset 1106
d0994e5bebce
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6822204: volatile fences should prefer lock:addl to actual mfence instructions
Reviewed-by: kvn, phh

     1 /*
     2  * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    26   (void)memmove(to, from, count * HeapWordSize);
    27 }
    29 static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    30 #ifdef AMD64
    31   switch (count) {
    32   case 8:  to[7] = from[7];
    33   case 7:  to[6] = from[6];
    34   case 6:  to[5] = from[5];
    35   case 5:  to[4] = from[4];
    36   case 4:  to[3] = from[3];
    37   case 3:  to[2] = from[2];
    38   case 2:  to[1] = from[1];
    39   case 1:  to[0] = from[0];
    40   case 0:  break;
    41   default:
    42     (void)memcpy(to, from, count * HeapWordSize);
    43     break;
    44   }
    45 #else
    46   (void)memcpy(to, from, count * HeapWordSize);
    47 #endif // AMD64
    48 }
    50 static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
    51   switch (count) {
    52   case 8:  to[7] = from[7];
    53   case 7:  to[6] = from[6];
    54   case 6:  to[5] = from[5];
    55   case 5:  to[4] = from[4];
    56   case 4:  to[3] = from[3];
    57   case 3:  to[2] = from[2];
    58   case 2:  to[1] = from[1];
    59   case 1:  to[0] = from[0];
    60   case 0:  break;
    61   default: while (count-- > 0) {
    62              *to++ = *from++;
    63            }
    64            break;
    65   }
    66 }
    68 static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    69   (void)memmove(to, from, count * HeapWordSize);
    70 }
    72 static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    73   pd_disjoint_words(from, to, count);
    74 }
    76 static void pd_conjoint_bytes(void* from, void* to, size_t count) {
    77   (void)memmove(to, from, count);
    78 }
    80 static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
    81   pd_conjoint_bytes(from, to, count);
    82 }
    84 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
    85   // FIXME
    86   (void)memmove(to, from, count << LogBytesPerShort);
    87 }
    89 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
    90   // FIXME
    91   (void)memmove(to, from, count << LogBytesPerInt);
    92 }
    94 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
    95 #ifdef AMD64
    96   assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
    97   pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
    98 #else
    99   // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.
   100   __asm {
   101     mov    eax, from;
   102     mov    edx, to;
   103     mov    ecx, count;
   104     cmp    eax, edx;
   105     jbe    downtest;
   106     jmp    uptest;
   107   up:
   108     fild   qword ptr [eax];
   109     fistp  qword ptr [edx];
   110     add    eax, 8;
   111     add    edx, 8;
   112   uptest:
   113     sub    ecx, 1;
   114     jge    up;
   115     jmp    done;
   116   down:
   117     fild   qword ptr [eax][ecx*8];
   118     fistp  qword ptr [edx][ecx*8];
   119   downtest:
   120     sub    ecx, 1;
   121     jge    down;
   122   done:;
   123   }
   124 #endif // AMD64
   125 }
   127 static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
   128   // Do better than this: inline memmove body  NEEDS CLEANUP
   129   if (from > to) {
   130     while (count-- > 0) {
   131       // Copy forwards
   132       *to++ = *from++;
   133     }
   134   } else {
   135     from += count - 1;
   136     to   += count - 1;
   137     while (count-- > 0) {
   138       // Copy backwards
   139       *to-- = *from--;
   140     }
   141   }
   142 }
   144 static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
   145 #ifdef AMD64
   146   pd_conjoint_bytes_atomic(from, to, count);
   147 #else
   148   pd_conjoint_bytes(from, to, count);
   149 #endif // AMD64
   150 }
   152 static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
   153   pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
   154 }
   156 static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
   157   pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
   158 }
   160 static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
   161   pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
   162 }
   164 static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
   165   pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
   166 }

mercurial