Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

bytegames.c File Reference


Detailed Description

Perform byte swapping, word swapping, byte-aligned accesses, non-aligned multi-byte items, etc.

General utilities for playing shell games with real machine bytes for both the real machine and the Java virtual machine.

Some machine architectures use little-endian versus big-endian byte ordering, some architectures do not natively support 2-byte or 4-byte or 8-byte word addressing on addesses that are not aligned to those boundaries. The JVM does not care about such things, but must accomodate real machine implementations in a way that they do not complain about it at run time. There area also functions here that provide such support. They typically are embedded in widely-used macros from cfmacros.h and util.h.

Control

$URL: https://svn.apache.org/path/name/bytegames.c $ $Id: bytegames.c 0 09/28/2005 dlydick $

Copyright 2005 The Apache Software Foundation or its licensors, as applicable.

Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Version:
$LastChangedRevision: 0 $
Date:
$LastChangedDate: 09/28/2005 $
Author:
$LastChangedBy: dlydick $ Original code contributed by Daniel Lydick on 09/28/2005.

Reference

Definition in file bytegames.c.

#include "arch.h"
#include "jvmcfg.h"
#include "util.h"

Go to the source code of this file.

Data Structures

union  eightbyte
 Structure for shuffling eight-byte values. More...
union  fourbyte
 Structure for shuffling four-byte values. More...
union  twobyte
 Structure for shuffling two-byte values. More...

Combine/split support for (jlong) and (jdouble).

The combine operation takes two jint words as the MS and LS words of a jlong or jdouble and returns a combined result. This is typically used for retrieving JVM local variables or operand stack parameters.

The split operation is the reverse. It takes a jlong or jdouble and extracts two jint words, typically for storage into a JVM local variable or operand stack parameter.

Todo:
Verify that all references to these routines load and store the results in the proper order! The MS word must be stored first (local variable 'n' or first PUSH() to operand stack). The LS word must be stored second (local variable 'n+1' or second PUSH() to operand stack). The retrieval from the operand stack must be LS word as the first POP(), MS word as the second POP() operation. This problem may occur especially in native.c and opcode.c.


jdouble bytegames_combine_jdouble (jint msword, jint lsword)
 Combine two jint words into a jdouble.
jlong bytegames_combine_jlong (jint msword, jint lsword)
 Combine two jint words into a jlong.
rvoid bytegames_split_jdouble (jdouble splitdouble, jint *msword, jint *lsword)
 Split a jdouble into two jint words.
rvoid bytegames_split_jlong (jlong splitlong, jint *msword, jint *lsword)
 Split a jlong into two jint words.

Unaligned multi-byte access support.

Store and retrieve arbitrary 2- and 4-byte values from unaligned addresses without causing SIGSEGV signals by performing 1-byte addressing on these locations.

The 2- and 4-byte functions are typically used for absorbing class file stream data into a ClassFile structure. Of particular interest is classfile_loadclassdata(), where it is used to retrieve many different types of 2- and 4-byte data. The 8-byte functions are used by class_get_constant_field_attribute() for retrieving jlong and jdouble constants.

ruint bytegames_getri4 (ruint *ptr4)
 4-byte version of bytegames_getrs2(), but performs two odd-byte accesses, not just one.
rulong bytegames_getrl8 (rulong *ptr8)
 8-byte version of bytegames_getri4(), but performs four odd-byte accesses, not just one.
rushort bytegames_getrs2 (rushort *ptr2)
 Retrieve any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.
rvoid bytegames_putri4 (ruint *ptr4, ruint val4)
 Store any generic 4-byte value (32 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.
rvoid bytegames_putrl8 (rulong *ptr8, rulong val8)
 Store any generic 8-byte value (64 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.This function is the inverse of bytegames_getrl8() above, which see for further explanation.
rvoid bytegames_putrs2 (rushort *ptr2, rushort val2)
 Store any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.

Byte swapping support.

Swap 2- and 4- and 8-byte values, especially for support of little-endian real machines.

Since the Java virtual machine is defined as a big-endian architecture, these functions are supplied to map between the big-endian JVM and a little-endian real machine implementation.

The 2- and 4-byte functions are typically used for swapping class file stream data as it is being absorbed into a ClassFile structure, as well as for other general uses. Of particular interest is classfile_loadclassdata(), where they are used to swap many different types of 2- and 4-byte data. The 8-byte functions are provided for completeness.

rulong bytegames_mix8 (rulong val)
 Mix up 8 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value in the same way as bytegames_swap8(), but store the words MS first, LS second.
rushort bytegames_swap2 (rushort val)
 Swap 2 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value.
ruint bytegames_swap4 (ruint val)
 Swap 4 bytes for a little-endian machine ruint value to a big-endian Java real machine implementation ruint value.
rulong bytegames_swap8 (rulong val)
 Swap 8 bytes for a little-endian machine rulong value to a big-endian Java real machine implementation rulong value.

Functions

static void bytegames_c_dummy (void)

Variables

static char * bytegames_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/bytegames.c $ $Id: bytegames.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable."


Function Documentation

static void bytegames_c_dummy void   )  [static]
 

Definition at line 54 of file bytegames.c.

rushort bytegames_getrs2 rushort ptr2  ) 
 

Retrieve any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.

This function was written to suppress SIGSEGV issues on GCC -m32 binaries on a Solaris 9.

Typical usage is in a situation of:

       rshort *pshort;
       ...
       val = *pshort;   ... If pshort is at odd address, throw SIGSEGV.
  
   

Thus convert to:

       rshort *pshort;
       ...
       val = getrs2(pshort);    ... No signal this way.
  
   

This causes two one-byte accesses to happen instead of a single two-byte access, eliminating the cause of SIGSEGV, unless, of course, the pointer is off in the weeds instead of looking at valid memory.

Parameters:
ptr2 Pointer to rushort location.
Returns:
16-bit value at *ptr2, properly byte swapped.

Definition at line 233 of file bytegames.c.

References twobyte::_byteval, and twobyte::_usval.

rvoid bytegames_putrs2 rushort ptr2,
rushort  val2
 

Store any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.

This function is the inverse of bytegames_getrs2() above, which see for further explanation.

Parameters:
ptr2 Pointer to rushort location.
val2 A rushort value to be stored.
Returns:
rvoid

Definition at line 268 of file bytegames.c.

References twobyte::_byteval, and twobyte::_usval.

ruint bytegames_getri4 ruint ptr4  ) 
 

4-byte version of bytegames_getrs2(), but performs two odd-byte accesses, not just one.

This causes four one-byte accesses to happen instead of a single four-byte access, eliminating the cause of SIGSEGV.

Parameters:
ptr4 Pointer to ruint location.
Returns:
32-bit value at *ptr4, properly byte swapped.

Definition at line 302 of file bytegames.c.

References fourbyte::_byteval, and fourbyte::_ruival.

rvoid bytegames_putri4 ruint ptr4,
ruint  val4
 

Store any generic 4-byte value (32 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.

This function is the inverse of bytegames_getri4() above, which see for further explanation.

Parameters:
ptr4 Pointer to ruint location.
val4 An ruint value to be stored.
Returns:
rvoid

Definition at line 339 of file bytegames.c.

References fourbyte::_byteval, and fourbyte::_ruival.

rulong bytegames_getrl8 rulong ptr8  ) 
 

8-byte version of bytegames_getri4(), but performs four odd-byte accesses, not just one.

This causes eight one-byte accesses to happen instead of a single eight-byte access, eliminating the cause of SIGSEGV.

Parameters:
ptr8 Pointer to rulong location.
Returns:
64-bit value from *ptr8, properly byte swapped.

Definition at line 376 of file bytegames.c.

References eightbyte::_byteval, eightbyte::_rulval, and bytegames_swap8().

rvoid bytegames_putrl8 rulong ptr8,
rulong  val8
 

Store any generic 8-byte value (64 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.This function is the inverse of bytegames_getrl8() above, which see for further explanation.

Attention:
NOTICE THAT THE TERM "long" and THE CAST (long) ARE FASTIDIOUSLY AVOIDED IN ORDER TO REMOVE ANY DOUBT AS TO WHAT IS A 32-BIT VALUE AND WHAT IS A 64-BIT VALUE!
Parameters:
ptr8 Pointer to rulong location.
val8 A rulong value to be stored.
Returns:
rvoid

Definition at line 421 of file bytegames.c.

References eightbyte::_byteval, eightbyte::_rulval, and bytegames_swap8().

rushort bytegames_swap2 rushort  val  ) 
 

Swap 2 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value.

Available but not used in big-endian architectures.

This routine is mapped for little-endian machines to MACHINE_JSHORT_SWAP().

   INPUT BYTE ORDER:    (a) (b)     rshort: (ab)
  
   OUTPUT BYTE ORDER:   (b) (a)     rshort: (ba)
  
   

Parameters:
val two-byte rushort to swap
Returns:
swapped byte version of val

Definition at line 497 of file bytegames.c.

References twobyte::_byteval, and twobyte::_usval.

ruint bytegames_swap4 ruint  val  ) 
 

Swap 4 bytes for a little-endian machine ruint value to a big-endian Java real machine implementation ruint value.

Available but not used in big-endian architectures.

This routine is mapped for little-endian machines to MACHINE_JINT_SWAP().

   INPUT BYTE ORDER:    (a) (b) (c) (d)     rint: (abcd)
  
   OUTPUT BYTE ORDER:   (d) (c) (b) (a)     rint: (dcba)
  
   

Parameters:
val four-byte ruint to swap
Returns:
swapped byte version of val

Definition at line 539 of file bytegames.c.

References fourbyte::_byteval, and fourbyte::_ruival.

rulong bytegames_swap8 rulong  val  ) 
 

Swap 8 bytes for a little-endian machine rulong value to a big-endian Java real machine implementation rulong value.

Available but not used in big-endian architectures.

This routine is mapped for little-endian machines to MACHINE_JLONG_SWAP().

   INPUT BYTE ORDER:  (a) (b) (c) (d) (e) (f) (g) (h)  rlong: (abcdefgh)
  
   OUTPUT BYTE ORDER: (h) (g) (f) (e) (d) (c) (b) (a)  rlong: (hgfedcba)
  
   

Parameters:
val eight-byte rulong to swap
Returns:
swapped byte version of val

Definition at line 586 of file bytegames.c.

References eightbyte::_byteval, and eightbyte::_rulval.

Referenced by bytegames_getrl8(), and bytegames_putrl8().

rulong bytegames_mix8 rulong  val  ) 
 

Mix up 8 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value in the same way as bytegames_swap8(), but store the words MS first, LS second.

Available but not used in big-endian architectures.

This routine is mapped for little-endian machines to MACHINE_JLONG_MIX().

   INPUT BYTE ORDER:  (a) (b) (c) (d) (e) (f) (g) (h)  rlong: (abcdefgh)
  
   OUTPUT BYTE ORDER: (d) (c) (b) (a) (h) (g) (f) (e)  rlong: (dcbahgfe)
  
   

Parameters:
val eight-byte rulong to swap/mix
Returns:
swapped/mixed byte version of val

Definition at line 643 of file bytegames.c.

References eightbyte::_byteval, and eightbyte::_rulval.

jlong bytegames_combine_jlong jint  msword,
jint  lsword
 

Combine two jint words into a jlong.

Pass in two sequential words as jint from the JVM stack frame or operand stack or any other appropriate source and return a result as jlong

Parameters:
msword Java integer at first index.
lsword Java integer at second index, directly subsequent to msword.
Returns:
concatenation as jlong, properly byte ordered.

Definition at line 722 of file bytegames.c.

References eightbyte::_intval, and eightbyte::_julval.

jdouble bytegames_combine_jdouble jint  msword,
jint  lsword
 

Combine two jint words into a jdouble.

Pass in two sequential words as jint from the JVM stack frame or operand stack or any other appropriate source and return a result as jdouble.

Parameters:
msword Java integer at first index.
lsword Java integer at second index, directly subsequent to msword.
Returns:
concatenation as jdouble , properly byte ordered.

Definition at line 752 of file bytegames.c.

References eightbyte::_intval, and eightbyte::_jdval.

rvoid bytegames_split_jlong jlong  splitlong,
jint msword,
jint lsword
 

Split a jlong into two jint words.

Pass in a jlong and return two words suitable for storing into a JVM stack frame as a pair of local variables or into the operand stack as two sequential words. The first receives the MS word, the second receives the LS word, which should be the next sequential stack frame local variable or operand stack location.

Parameters:
[in] splitlong Java long integer to split.
[out] msword Address of MS half of split value.
[out] lsword Address of LS half of split value.
Returns:
rvoid

Definition at line 785 of file bytegames.c.

References eightbyte::_intval, and eightbyte::_julval.

Referenced by native_run_local_return_jlong(), and opcode_run().

rvoid bytegames_split_jdouble jdouble  splitdouble,
jint msword,
jint lsword
 

Split a jdouble into two jint words.

Pass in a jlong and return two words suitable for storing into a JVM stack frame as a pair of local variables or into the operand stack as two sequential words. The first receives the MS word, the second receives the LS word, which should be the next sequential stack frame local variable or operand stack location.

Parameters:
[in] splitdouble Java double float to split.
[out] msword Address of MS half of split value.
[out] lsword Address of LS half of split value.
Returns:
rvoid

Definition at line 820 of file bytegames.c.

References eightbyte::_intval, and eightbyte::_jdval.

Referenced by native_run_local_return_jdouble(), and opcode_run().


Variable Documentation

char* bytegames_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/bytegames.c $ $Id: bytegames.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." [static]
 

Definition at line 54 of file bytegames.c.


Generated on Fri Sep 30 18:59:52 2005 by  doxygen 1.4.4