< prev index next >

src/share/vm/runtime/sharedRuntime.cpp

Print this page
rev 10541 : Adapter sharing fix


2173  private:
2174   enum {
2175     _basic_type_bits = 4,
2176     _basic_type_mask = right_n_bits(_basic_type_bits),
2177     _basic_types_per_int = BitsPerInt / _basic_type_bits,
2178     _compact_int_count = 3
2179   };
2180   // TO DO:  Consider integrating this with a more global scheme for compressing signatures.
2181   // For now, 4 bits per components (plus T_VOID gaps after double/long) is not excessive.
2182 
2183   union {
2184     int  _compact[_compact_int_count];
2185     int* _fingerprint;
2186   } _value;
2187   int _length; // A negative length indicates the fingerprint is in the compact form,
2188                // Otherwise _value._fingerprint is the array.
2189 
2190   // Remap BasicTypes that are handled equivalently by the adapters.
2191   // These are correct for the current system but someday it might be
2192   // necessary to make this mapping platform dependent.
2193   static int adapter_encoding(BasicType in) {
2194     switch (in) {
2195       case T_BOOLEAN:
2196       case T_BYTE:
2197       case T_SHORT:
2198       case T_CHAR:
2199         // There are all promoted to T_INT in the calling convention





2200         return T_INT;


2201 
2202       case T_OBJECT:
2203       case T_VALUETYPE:
2204       case T_ARRAY:
2205         // In other words, we assume that any register good enough for
2206         // an int or long is good enough for a managed pointer.
2207 #ifdef _LP64
2208         return T_LONG;
2209 #else
2210         return T_INT;
2211 #endif
2212 
2213       case T_INT:
2214       case T_LONG:
2215       case T_FLOAT:
2216       case T_DOUBLE:
2217       case T_VOID:
2218         return in;
2219 
2220       default:


2227   AdapterFingerPrint(int total_args_passed, BasicType* sig_bt) {
2228     // The fingerprint is based on the BasicType signature encoded
2229     // into an array of ints with eight entries per int.
2230     int* ptr;
2231     int len = (total_args_passed + (_basic_types_per_int-1)) / _basic_types_per_int;
2232     if (len <= _compact_int_count) {
2233       assert(_compact_int_count == 3, "else change next line");
2234       _value._compact[0] = _value._compact[1] = _value._compact[2] = 0;
2235       // Storing the signature encoded as signed chars hits about 98%
2236       // of the time.
2237       _length = -len;
2238       ptr = _value._compact;
2239     } else {
2240       _length = len;
2241       _value._fingerprint = NEW_C_HEAP_ARRAY(int, _length, mtCode);
2242       ptr = _value._fingerprint;
2243     }
2244 
2245     // Now pack the BasicTypes with 8 per int
2246     int sig_index = 0;



2247     for (int index = 0; index < len; index++) {
2248       int value = 0;
2249       for (int byte = 0; byte < _basic_types_per_int; byte++) {
2250         int bt = ((sig_index < total_args_passed)
2251                   ? adapter_encoding(sig_bt[sig_index++])
2252                   : 0);













2253         assert((bt & _basic_type_mask) == bt, "must fit in 4 bits");
2254         value = (value << _basic_type_bits) | bt;
2255       }
2256       ptr[index] = value;
2257     }

2258   }
2259 
2260   ~AdapterFingerPrint() {
2261     if (_length > 0) {
2262       FREE_C_HEAP_ARRAY(int, _value._fingerprint);
2263     }
2264   }
2265 
2266   int value(int index) {
2267     if (_length < 0) {
2268       return _value._compact[index];
2269     }
2270     return _value._fingerprint[index];
2271   }
2272   int length() {
2273     if (_length < 0) return -_length;
2274     return _length;
2275   }
2276 
2277   bool is_compact() {




2173  private:
2174   enum {
2175     _basic_type_bits = 4,
2176     _basic_type_mask = right_n_bits(_basic_type_bits),
2177     _basic_types_per_int = BitsPerInt / _basic_type_bits,
2178     _compact_int_count = 3
2179   };
2180   // TO DO:  Consider integrating this with a more global scheme for compressing signatures.
2181   // For now, 4 bits per components (plus T_VOID gaps after double/long) is not excessive.
2182 
2183   union {
2184     int  _compact[_compact_int_count];
2185     int* _fingerprint;
2186   } _value;
2187   int _length; // A negative length indicates the fingerprint is in the compact form,
2188                // Otherwise _value._fingerprint is the array.
2189 
2190   // Remap BasicTypes that are handled equivalently by the adapters.
2191   // These are correct for the current system but someday it might be
2192   // necessary to make this mapping platform dependent.
2193   static int adapter_encoding(BasicType in, bool is_valuetype) {
2194     switch (in) {
2195       case T_BOOLEAN:
2196       case T_BYTE:
2197       case T_SHORT:
2198       case T_CHAR: {
2199         if (is_valuetype) {
2200           // Do not widen value type field types
2201           assert(ValueTypePassFieldsAsArgs, "must be enabled");
2202           return in;
2203         } else {
2204           // They are all promoted to T_INT in the calling convention
2205           return T_INT;
2206         }
2207       }
2208 
2209       case T_OBJECT:
2210       case T_VALUETYPE:
2211       case T_ARRAY:
2212         // In other words, we assume that any register good enough for
2213         // an int or long is good enough for a managed pointer.
2214 #ifdef _LP64
2215         return T_LONG;
2216 #else
2217         return T_INT;
2218 #endif
2219 
2220       case T_INT:
2221       case T_LONG:
2222       case T_FLOAT:
2223       case T_DOUBLE:
2224       case T_VOID:
2225         return in;
2226 
2227       default:


2234   AdapterFingerPrint(int total_args_passed, BasicType* sig_bt) {
2235     // The fingerprint is based on the BasicType signature encoded
2236     // into an array of ints with eight entries per int.
2237     int* ptr;
2238     int len = (total_args_passed + (_basic_types_per_int-1)) / _basic_types_per_int;
2239     if (len <= _compact_int_count) {
2240       assert(_compact_int_count == 3, "else change next line");
2241       _value._compact[0] = _value._compact[1] = _value._compact[2] = 0;
2242       // Storing the signature encoded as signed chars hits about 98%
2243       // of the time.
2244       _length = -len;
2245       ptr = _value._compact;
2246     } else {
2247       _length = len;
2248       _value._fingerprint = NEW_C_HEAP_ARRAY(int, _length, mtCode);
2249       ptr = _value._fingerprint;
2250     }
2251 
2252     // Now pack the BasicTypes with 8 per int
2253     int sig_index = 0;
2254     BasicType prev_sbt = T_ILLEGAL;
2255     bool is_valuetype = false;
2256     int vt_count = 0;
2257     for (int index = 0; index < len; index++) {
2258       int value = 0;
2259       for (int byte = 0; byte < _basic_types_per_int; byte++) {
2260         int bt = 0;
2261         if (sig_index < total_args_passed) {
2262           BasicType sbt = sig_bt[sig_index++];
2263           if (ValueTypePassFieldsAsArgs && sbt == T_VALUETYPE) {
2264             // Found start of value type in signature
2265             vt_count++;
2266             continue;
2267           } else if (sbt == T_VOID && prev_sbt != T_LONG && prev_sbt != T_DOUBLE) {
2268             // Found end of value type in signature
2269             vt_count--;
2270             assert(vt_count >= 0, "invalid vt_count");
2271             continue;
2272           }
2273           bt = adapter_encoding(sbt, vt_count > 0);
2274           prev_sbt = sbt;
2275         }
2276         assert((bt & _basic_type_mask) == bt, "must fit in 4 bits");
2277         value = (value << _basic_type_bits) | bt;
2278       }
2279       ptr[index] = value;
2280     }
2281     assert(vt_count == 0, "invalid vt_count");
2282   }
2283 
2284   ~AdapterFingerPrint() {
2285     if (_length > 0) {
2286       FREE_C_HEAP_ARRAY(int, _value._fingerprint);
2287     }
2288   }
2289 
2290   int value(int index) {
2291     if (_length < 0) {
2292       return _value._compact[index];
2293     }
2294     return _value._fingerprint[index];
2295   }
2296   int length() {
2297     if (_length < 0) return -_length;
2298     return _length;
2299   }
2300 
2301   bool is_compact() {


< prev index next >