src/cpu/ppc/vm/templateTable_ppc_64.cpp

Print this page
rev 6728 : 8050942: PPC64: implement template interpreter for ppc64le
Contributed-by: asmundak@google.com


 171   Label L_patch_done;
 172 
 173   switch (new_bc) {
 174     case Bytecodes::_fast_aputfield:
 175     case Bytecodes::_fast_bputfield:
 176     case Bytecodes::_fast_cputfield:
 177     case Bytecodes::_fast_dputfield:
 178     case Bytecodes::_fast_fputfield:
 179     case Bytecodes::_fast_iputfield:
 180     case Bytecodes::_fast_lputfield:
 181     case Bytecodes::_fast_sputfield:
 182     {
 183       // We skip bytecode quickening for putfield instructions when
 184       // the put_code written to the constant pool cache is zero.
 185       // This is required so that every execution of this instruction
 186       // calls out to InterpreterRuntime::resolve_get_put to do
 187       // additional, required work.
 188       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 189       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 190       __ get_cache_and_index_at_bcp(Rtemp /* dst = cache */, 1);
 191       // Big Endian: ((*(cache+indices))>>((1+byte_no)*8))&0xFF



 192       __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (1 + byte_no), Rtemp);

 193       __ cmpwi(CCR0, Rnew_bc, 0);
 194       __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc);
 195       __ beq(CCR0, L_patch_done);
 196       // __ isync(); // acquire not needed
 197       break;
 198     }
 199 
 200     default:
 201       assert(byte_no == -1, "sanity");
 202       if (load_bc_into_bc_reg) {
 203         __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc);
 204       }
 205   }
 206 
 207   if (JvmtiExport::can_post_breakpoint()) {
 208     Label L_fast_patch;
 209     __ lbz(Rtemp, 0, R14_bcp);
 210     __ cmpwi(CCR0, Rtemp, (unsigned int)(unsigned char)Bytecodes::_breakpoint);
 211     __ bne(CCR0, L_fast_patch);
 212     // Perform the quickening, slowly, in the bowels of the breakpoint table.


1821   __ dispatch_next(vtos);
1822 }
1823 
1824 void TemplateTable::tableswitch() {
1825   transition(itos, vtos);
1826 
1827   Label Ldispatch, Ldefault_case;
1828   Register Rlow_byte         = R3_ARG1,
1829            Rindex            = Rlow_byte,
1830            Rhigh_byte        = R4_ARG2,
1831            Rdef_offset_addr  = R5_ARG3, // is going to contain address of default offset
1832            Rscratch1         = R11_scratch1,
1833            Rscratch2         = R12_scratch2,
1834            Roffset           = R6_ARG4;
1835 
1836   // Align bcp.
1837   __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt);
1838   __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt));
1839 
1840   // Load lo & hi.
1841   __ lwz(Rlow_byte, BytesPerInt, Rdef_offset_addr);
1842   __ lwz(Rhigh_byte, BytesPerInt * 2, Rdef_offset_addr);
1843 
1844   // Check for default case (=index outside [low,high]).
1845   __ cmpw(CCR0, R17_tos, Rlow_byte);
1846   __ cmpw(CCR1, R17_tos, Rhigh_byte);
1847   __ blt(CCR0, Ldefault_case);
1848   __ bgt(CCR1, Ldefault_case);
1849 
1850   // Lookup dispatch offset.
1851   __ sub(Rindex, R17_tos, Rlow_byte);
1852   __ extsw(Rindex, Rindex);
1853   __ profile_switch_case(Rindex, Rhigh_byte /* scratch */, Rscratch1, Rscratch2);
1854   __ sldi(Rindex, Rindex, LogBytesPerInt);
1855   __ addi(Rindex, Rindex, 3 * BytesPerInt);




1856   __ lwax(Roffset, Rdef_offset_addr, Rindex);

1857   __ b(Ldispatch);
1858 
1859   __ bind(Ldefault_case);
1860   __ profile_switch_default(Rhigh_byte, Rscratch1);
1861   __ lwa(Roffset, 0, Rdef_offset_addr);
1862 
1863   __ bind(Ldispatch);
1864 
1865   __ add(R14_bcp, Roffset, R14_bcp);
1866   __ dispatch_next(vtos);
1867 }
1868 
1869 void TemplateTable::lookupswitch() {
1870   transition(itos, itos);
1871   __ stop("lookupswitch bytecode should have been rewritten");
1872 }
1873 
1874 // Table switch using linear search through cases.
1875 // Bytecode stream format:
1876 // Bytecode (1) | 4-byte padding | default offset (4) | count (4) | value/offset pair1 (8) | value/offset pair2 (8) | ...
1877 // Note: Everything is big-endian format here. So on little endian machines, we have to revers offset and count and cmp value.
1878 void TemplateTable::fast_linearswitch() {
1879   transition(itos, vtos);
1880 
1881   Label Lloop_entry, Lsearch_loop, Lfound, Lcontinue_execution, Ldefault_case;
1882 
1883   Register Rcount           = R3_ARG1,
1884            Rcurrent_pair    = R4_ARG2,
1885            Rdef_offset_addr = R5_ARG3, // Is going to contain address of default offset.
1886            Roffset          = R31,     // Might need to survive C call.
1887            Rvalue           = R12_scratch2,
1888            Rscratch         = R11_scratch1,
1889            Rcmp_value       = R17_tos;
1890 
1891   // Align bcp.
1892   __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt);
1893   __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt));
1894 
1895   // Setup loop counter and limit.
1896   __ lwz(Rcount, BytesPerInt, Rdef_offset_addr);    // Load count.
1897   __ addi(Rcurrent_pair, Rdef_offset_addr, 2 * BytesPerInt); // Rcurrent_pair now points to first pair.
1898 
1899   // Set up search loop.
1900   __ cmpwi(CCR0, Rcount, 0);
1901   __ beq(CCR0, Ldefault_case);
1902 
1903   __ mtctr(Rcount);
1904 
1905   // linear table search
1906   __ bind(Lsearch_loop);
1907 
1908   __ lwz(Rvalue, 0, Rcurrent_pair);
1909   __ lwa(Roffset, 1 * BytesPerInt, Rcurrent_pair);


1910 
1911   __ cmpw(CCR0, Rvalue, Rcmp_value);
1912   __ beq(CCR0, Lfound);
1913 
1914   __ addi(Rcurrent_pair, Rcurrent_pair, 2 * BytesPerInt);
1915   __ bdnz(Lsearch_loop);
1916 
1917   // default case
1918   __ bind(Ldefault_case);
1919 
1920   __ lwa(Roffset, 0, Rdef_offset_addr);
1921   if (ProfileInterpreter) {
1922     __ profile_switch_default(Rdef_offset_addr, Rcount/* scratch */);
1923     __ b(Lcontinue_execution);
1924   }
1925 
1926   // Entry found, skip Roffset bytecodes and continue.
1927   __ bind(Lfound);
1928   if (ProfileInterpreter) {
1929     // Calc the num of the pair we hit. Careful, Rcurrent_pair points 2 ints
1930     // beyond the actual current pair due to the auto update load above!
1931     __ sub(Rcurrent_pair, Rcurrent_pair, Rdef_offset_addr);
1932     __ addi(Rcurrent_pair, Rcurrent_pair, - 2 * BytesPerInt);
1933     __ srdi(Rcurrent_pair, Rcurrent_pair, LogBytesPerInt + 1);
1934     __ profile_switch_case(Rcurrent_pair, Rcount /*scratch*/, Rdef_offset_addr/*scratch*/, Rscratch);
1935     __ bind(Lcontinue_execution);
1936   }
1937   __ add(R14_bcp, Roffset, R14_bcp);
1938   __ dispatch_next(vtos);
1939 }
1940 


1972 
1973   // register allocation
1974   const Register Rkey     = R17_tos;          // already set (tosca)
1975   const Register Rarray   = R3_ARG1;
1976   const Register Ri       = R4_ARG2;
1977   const Register Rj       = R5_ARG3;
1978   const Register Rh       = R6_ARG4;
1979   const Register Rscratch = R11_scratch1;
1980 
1981   const int log_entry_size = 3;
1982   const int entry_size = 1 << log_entry_size;
1983 
1984   Label found;
1985 
1986   // Find Array start,
1987   __ addi(Rarray, R14_bcp, 3 * BytesPerInt);
1988   __ clrrdi(Rarray, Rarray, log2_long((jlong)BytesPerInt));
1989 
1990   // initialize i & j
1991   __ li(Ri,0);
1992   __ lwz(Rj, -BytesPerInt, Rarray);
1993 
1994   // and start.
1995   Label entry;
1996   __ b(entry);
1997 
1998   // binary search loop
1999   { Label loop;
2000     __ bind(loop);
2001     // int h = (i + j) >> 1;
2002     __ srdi(Rh, Rh, 1);
2003     // if (key < array[h].fast_match()) {
2004     //   j = h;
2005     // } else {
2006     //   i = h;
2007     // }
2008     __ sldi(Rscratch, Rh, log_entry_size);



2009     __ lwzx(Rscratch, Rscratch, Rarray);

2010 
2011     // if (key < current value)
2012     //   Rh = Rj
2013     // else
2014     //   Rh = Ri
2015     Label Lgreater;
2016     __ cmpw(CCR0, Rkey, Rscratch);
2017     __ bge(CCR0, Lgreater);
2018     __ mr(Rj, Rh);
2019     __ b(entry);
2020     __ bind(Lgreater);
2021     __ mr(Ri, Rh);
2022 
2023     // while (i+1 < j)
2024     __ bind(entry);
2025     __ addi(Rscratch, Ri, 1);
2026     __ cmpw(CCR0, Rscratch, Rj);
2027     __ add(Rh, Ri, Rj); // start h = i + j >> 1;
2028 
2029     __ blt(CCR0, loop);
2030   }
2031 
2032   // End of binary search, result index is i (must check again!).
2033   Label default_case;
2034   Label continue_execution;
2035   if (ProfileInterpreter) {
2036     __ mr(Rh, Ri);              // Save index in i for profiling.
2037   }
2038   // Ri = value offset
2039   __ sldi(Ri, Ri, log_entry_size);
2040   __ add(Ri, Ri, Rarray);
2041   __ lwz(Rscratch, 0, Ri);
2042 
2043   Label not_found;
2044   // Ri = offset offset
2045   __ cmpw(CCR0, Rkey, Rscratch);
2046   __ beq(CCR0, not_found);
2047   // entry not found -> j = default offset
2048   __ lwz(Rj, -2 * BytesPerInt, Rarray);
2049   __ b(default_case);
2050 
2051   __ bind(not_found);
2052   // entry found -> j = offset
2053   __ profile_switch_case(Rh, Rj, Rscratch, Rkey);
2054   __ lwz(Rj, BytesPerInt, Ri);
2055 
2056   if (ProfileInterpreter) {
2057     __ b(continue_execution);
2058   }
2059 
2060   __ bind(default_case); // fall through (if not profiling)
2061   __ profile_switch_default(Ri, Rscratch);
2062 
2063   __ bind(continue_execution);
2064 
2065   __ extsw(Rj, Rj);
2066   __ add(R14_bcp, Rj, R14_bcp);
2067   __ dispatch_next(vtos);
2068 }
2069 
2070 void TemplateTable::_return(TosState state) {
2071   transition(state, state);
2072   assert(_desc->calls_vm(),
2073          "inconsistent calls_vm information"); // call in remove_activation
2074 


2129 // ConstantPoolCacheEntry::bytecode_2() and ConstantPoolCacheEntry::f1();
2130 
2131 // Call into the VM if call site is not yet resolved
2132 //
2133 // Input regs:
2134 //   - None, all passed regs are outputs.
2135 //
2136 // Returns:
2137 //   - Rcache:  The const pool cache entry that contains the resolved result.
2138 //   - Rresult: Either noreg or output for f1/f2.
2139 //
2140 // Kills:
2141 //   - Rscratch
2142 void TemplateTable::resolve_cache_and_index(int byte_no, Register Rcache, Register Rscratch, size_t index_size) {
2143 
2144   __ get_cache_and_index_at_bcp(Rcache, 1, index_size);
2145   Label Lresolved, Ldone;
2146 
2147   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2148   // We are resolved if the indices offset contains the current bytecode.
2149   // Big Endian:


2150   __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (byte_no + 1), Rcache);

2151   // Acquire by cmp-br-isync (see below).
2152   __ cmpdi(CCR0, Rscratch, (int)bytecode());
2153   __ beq(CCR0, Lresolved);
2154 
2155   address entry = NULL;
2156   switch (bytecode()) {
2157     case Bytecodes::_getstatic      : // fall through
2158     case Bytecodes::_putstatic      : // fall through
2159     case Bytecodes::_getfield       : // fall through
2160     case Bytecodes::_putfield       : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
2161     case Bytecodes::_invokevirtual  : // fall through
2162     case Bytecodes::_invokespecial  : // fall through
2163     case Bytecodes::_invokestatic   : // fall through
2164     case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break;
2165     case Bytecodes::_invokehandle   : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle); break;
2166     case Bytecodes::_invokedynamic  : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break;
2167     default                         : ShouldNotReachHere(); break;
2168   }
2169   __ li(R4_ARG2, (int)bytecode());
2170   __ call_VM(noreg, entry, R4_ARG2, true);




 171   Label L_patch_done;
 172 
 173   switch (new_bc) {
 174     case Bytecodes::_fast_aputfield:
 175     case Bytecodes::_fast_bputfield:
 176     case Bytecodes::_fast_cputfield:
 177     case Bytecodes::_fast_dputfield:
 178     case Bytecodes::_fast_fputfield:
 179     case Bytecodes::_fast_iputfield:
 180     case Bytecodes::_fast_lputfield:
 181     case Bytecodes::_fast_sputfield:
 182     {
 183       // We skip bytecode quickening for putfield instructions when
 184       // the put_code written to the constant pool cache is zero.
 185       // This is required so that every execution of this instruction
 186       // calls out to InterpreterRuntime::resolve_get_put to do
 187       // additional, required work.
 188       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 189       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 190       __ get_cache_and_index_at_bcp(Rtemp /* dst = cache */, 1);
 191       // ((*(cache+indices))>>((1+byte_no)*8))&0xFF:
 192 #if defined(VM_LITTLE_ENDIAN)
 193       __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 1 + byte_no, Rtemp);
 194 #else
 195       __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (1 + byte_no), Rtemp);
 196 #endif
 197       __ cmpwi(CCR0, Rnew_bc, 0);
 198       __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc);
 199       __ beq(CCR0, L_patch_done);
 200       // __ isync(); // acquire not needed
 201       break;
 202     }
 203 
 204     default:
 205       assert(byte_no == -1, "sanity");
 206       if (load_bc_into_bc_reg) {
 207         __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc);
 208       }
 209   }
 210 
 211   if (JvmtiExport::can_post_breakpoint()) {
 212     Label L_fast_patch;
 213     __ lbz(Rtemp, 0, R14_bcp);
 214     __ cmpwi(CCR0, Rtemp, (unsigned int)(unsigned char)Bytecodes::_breakpoint);
 215     __ bne(CCR0, L_fast_patch);
 216     // Perform the quickening, slowly, in the bowels of the breakpoint table.


1825   __ dispatch_next(vtos);
1826 }
1827 
1828 void TemplateTable::tableswitch() {
1829   transition(itos, vtos);
1830 
1831   Label Ldispatch, Ldefault_case;
1832   Register Rlow_byte         = R3_ARG1,
1833            Rindex            = Rlow_byte,
1834            Rhigh_byte        = R4_ARG2,
1835            Rdef_offset_addr  = R5_ARG3, // is going to contain address of default offset
1836            Rscratch1         = R11_scratch1,
1837            Rscratch2         = R12_scratch2,
1838            Roffset           = R6_ARG4;
1839 
1840   // Align bcp.
1841   __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt);
1842   __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt));
1843 
1844   // Load lo & hi.
1845   __ get_u4(Rlow_byte, Rdef_offset_addr, BytesPerInt, InterpreterMacroAssembler::Unsigned);
1846   __ get_u4(Rhigh_byte, Rdef_offset_addr, 2 *BytesPerInt, InterpreterMacroAssembler::Unsigned);
1847 
1848   // Check for default case (=index outside [low,high]).
1849   __ cmpw(CCR0, R17_tos, Rlow_byte);
1850   __ cmpw(CCR1, R17_tos, Rhigh_byte);
1851   __ blt(CCR0, Ldefault_case);
1852   __ bgt(CCR1, Ldefault_case);
1853 
1854   // Lookup dispatch offset.
1855   __ sub(Rindex, R17_tos, Rlow_byte);
1856   __ extsw(Rindex, Rindex);
1857   __ profile_switch_case(Rindex, Rhigh_byte /* scratch */, Rscratch1, Rscratch2);
1858   __ sldi(Rindex, Rindex, LogBytesPerInt);
1859   __ addi(Rindex, Rindex, 3 * BytesPerInt);
1860 #if defined(VM_LITTLE_ENDIAN)
1861   __ lwbrx(Roffset, Rdef_offset_addr, Rindex);
1862   __ extsw(Roffset, Roffset);
1863 #else
1864   __ lwax(Roffset, Rdef_offset_addr, Rindex);
1865 #endif
1866   __ b(Ldispatch);
1867 
1868   __ bind(Ldefault_case);
1869   __ profile_switch_default(Rhigh_byte, Rscratch1);
1870   __ get_u4(Roffset, Rdef_offset_addr, 0, InterpreterMacroAssembler::Signed);
1871 
1872   __ bind(Ldispatch);
1873 
1874   __ add(R14_bcp, Roffset, R14_bcp);
1875   __ dispatch_next(vtos);
1876 }
1877 
1878 void TemplateTable::lookupswitch() {
1879   transition(itos, itos);
1880   __ stop("lookupswitch bytecode should have been rewritten");
1881 }
1882 
1883 // Table switch using linear search through cases.
1884 // Bytecode stream format:
1885 // Bytecode (1) | 4-byte padding | default offset (4) | count (4) | value/offset pair1 (8) | value/offset pair2 (8) | ...
1886 // Note: Everything is big-endian format here.
1887 void TemplateTable::fast_linearswitch() {
1888   transition(itos, vtos);
1889 
1890   Label Lloop_entry, Lsearch_loop, Lfound, Lcontinue_execution, Ldefault_case;
1891 
1892   Register Rcount           = R3_ARG1,
1893            Rcurrent_pair    = R4_ARG2,
1894            Rdef_offset_addr = R5_ARG3, // Is going to contain address of default offset.
1895            Roffset          = R31,     // Might need to survive C call.
1896            Rvalue           = R12_scratch2,
1897            Rscratch         = R11_scratch1,
1898            Rcmp_value       = R17_tos;
1899 
1900   // Align bcp.
1901   __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt);
1902   __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt));
1903 
1904   // Setup loop counter and limit.
1905   __ get_u4(Rcount, Rdef_offset_addr, BytesPerInt, InterpreterMacroAssembler::Unsigned);
1906   __ addi(Rcurrent_pair, Rdef_offset_addr, 2 * BytesPerInt); // Rcurrent_pair now points to first pair.
1907 
1908   // Set up search loop.
1909   __ cmpwi(CCR0, Rcount, 0);
1910   __ beq(CCR0, Ldefault_case);
1911 
1912   __ mtctr(Rcount);
1913 
1914   // linear table search
1915   __ bind(Lsearch_loop);
1916 
1917   // TODO(asmundak): there is no need to fetch bytecode offset immediately,
1918   // do it only when we have found the matching value.
1919   __ get_u4(Rvalue, Rcurrent_pair, 0, InterpreterMacroAssembler::Unsigned);
1920   __ get_u4(Roffset, Rcurrent_pair, BytesPerInt, InterpreterMacroAssembler::Signed);
1921 
1922   __ cmpw(CCR0, Rvalue, Rcmp_value);
1923   __ beq(CCR0, Lfound);
1924 
1925   __ addi(Rcurrent_pair, Rcurrent_pair, 2 * BytesPerInt);
1926   __ bdnz(Lsearch_loop);
1927 
1928   // default case
1929   __ bind(Ldefault_case);
1930 
1931   __ get_u4(Roffset, Rdef_offset_addr, 0, InterpreterMacroAssembler::Unsigned);
1932   if (ProfileInterpreter) {
1933     __ profile_switch_default(Rdef_offset_addr, Rcount/* scratch */);
1934     __ b(Lcontinue_execution);
1935   }
1936 
1937   // Entry found, skip Roffset bytecodes and continue.
1938   __ bind(Lfound);
1939   if (ProfileInterpreter) {
1940     // Calc the num of the pair we hit. Careful, Rcurrent_pair points 2 ints
1941     // beyond the actual current pair due to the auto update load above!
1942     __ sub(Rcurrent_pair, Rcurrent_pair, Rdef_offset_addr);
1943     __ addi(Rcurrent_pair, Rcurrent_pair, - 2 * BytesPerInt);
1944     __ srdi(Rcurrent_pair, Rcurrent_pair, LogBytesPerInt + 1);
1945     __ profile_switch_case(Rcurrent_pair, Rcount /*scratch*/, Rdef_offset_addr/*scratch*/, Rscratch);
1946     __ bind(Lcontinue_execution);
1947   }
1948   __ add(R14_bcp, Roffset, R14_bcp);
1949   __ dispatch_next(vtos);
1950 }
1951 


1983 
1984   // register allocation
1985   const Register Rkey     = R17_tos;          // already set (tosca)
1986   const Register Rarray   = R3_ARG1;
1987   const Register Ri       = R4_ARG2;
1988   const Register Rj       = R5_ARG3;
1989   const Register Rh       = R6_ARG4;
1990   const Register Rscratch = R11_scratch1;
1991 
1992   const int log_entry_size = 3;
1993   const int entry_size = 1 << log_entry_size;
1994 
1995   Label found;
1996 
1997   // Find Array start,
1998   __ addi(Rarray, R14_bcp, 3 * BytesPerInt);
1999   __ clrrdi(Rarray, Rarray, log2_long((jlong)BytesPerInt));
2000 
2001   // initialize i & j
2002   __ li(Ri,0);
2003   __ get_u4(Rj, Rarray, -BytesPerInt, InterpreterMacroAssembler::Unsigned);
2004 
2005   // and start.
2006   Label entry;
2007   __ b(entry);
2008 
2009   // binary search loop
2010   { Label loop;
2011     __ bind(loop);
2012     // int h = (i + j) >> 1;
2013     __ srdi(Rh, Rh, 1);
2014     // if (key < array[h].fast_match()) {
2015     //   j = h;
2016     // } else {
2017     //   i = h;
2018     // }
2019     __ sldi(Rscratch, Rh, log_entry_size);
2020 #if defined(VM_LITTLE_ENDIAN)
2021     __ lwbrx(Rscratch, Rscratch, Rarray);
2022 #else
2023     __ lwzx(Rscratch, Rscratch, Rarray);
2024 #endif
2025 
2026     // if (key < current value)
2027     //   Rh = Rj
2028     // else
2029     //   Rh = Ri
2030     Label Lgreater;
2031     __ cmpw(CCR0, Rkey, Rscratch);
2032     __ bge(CCR0, Lgreater);
2033     __ mr(Rj, Rh);
2034     __ b(entry);
2035     __ bind(Lgreater);
2036     __ mr(Ri, Rh);
2037 
2038     // while (i+1 < j)
2039     __ bind(entry);
2040     __ addi(Rscratch, Ri, 1);
2041     __ cmpw(CCR0, Rscratch, Rj);
2042     __ add(Rh, Ri, Rj); // start h = i + j >> 1;
2043 
2044     __ blt(CCR0, loop);
2045   }
2046 
2047   // End of binary search, result index is i (must check again!).
2048   Label default_case;
2049   Label continue_execution;
2050   if (ProfileInterpreter) {
2051     __ mr(Rh, Ri);              // Save index in i for profiling.
2052   }
2053   // Ri = value offset
2054   __ sldi(Ri, Ri, log_entry_size);
2055   __ add(Ri, Ri, Rarray);
2056   __ get_u4(Rscratch, Ri, 0, InterpreterMacroAssembler::Unsigned);
2057 
2058   Label not_found;
2059   // Ri = offset offset
2060   __ cmpw(CCR0, Rkey, Rscratch);
2061   __ beq(CCR0, not_found);
2062   // entry not found -> j = default offset
2063   __ get_u4(Rj, Rarray, -2 * BytesPerInt, InterpreterMacroAssembler::Unsigned);
2064   __ b(default_case);
2065 
2066   __ bind(not_found);
2067   // entry found -> j = offset
2068   __ profile_switch_case(Rh, Rj, Rscratch, Rkey);
2069   __ get_u4(Rj, Ri, BytesPerInt, InterpreterMacroAssembler::Unsigned);
2070 
2071   if (ProfileInterpreter) {
2072     __ b(continue_execution);
2073   }
2074 
2075   __ bind(default_case); // fall through (if not profiling)
2076   __ profile_switch_default(Ri, Rscratch);
2077 
2078   __ bind(continue_execution);
2079 
2080   __ extsw(Rj, Rj);
2081   __ add(R14_bcp, Rj, R14_bcp);
2082   __ dispatch_next(vtos);
2083 }
2084 
2085 void TemplateTable::_return(TosState state) {
2086   transition(state, state);
2087   assert(_desc->calls_vm(),
2088          "inconsistent calls_vm information"); // call in remove_activation
2089 


2144 // ConstantPoolCacheEntry::bytecode_2() and ConstantPoolCacheEntry::f1();
2145 
2146 // Call into the VM if call site is not yet resolved
2147 //
2148 // Input regs:
2149 //   - None, all passed regs are outputs.
2150 //
2151 // Returns:
2152 //   - Rcache:  The const pool cache entry that contains the resolved result.
2153 //   - Rresult: Either noreg or output for f1/f2.
2154 //
2155 // Kills:
2156 //   - Rscratch
2157 void TemplateTable::resolve_cache_and_index(int byte_no, Register Rcache, Register Rscratch, size_t index_size) {
2158 
2159   __ get_cache_and_index_at_bcp(Rcache, 1, index_size);
2160   Label Lresolved, Ldone;
2161 
2162   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2163   // We are resolved if the indices offset contains the current bytecode.
2164 #if defined(VM_LITTLE_ENDIAN)
2165   __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + byte_no + 1, Rcache);
2166 #else
2167   __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (byte_no + 1), Rcache);
2168 #endif
2169   // Acquire by cmp-br-isync (see below).
2170   __ cmpdi(CCR0, Rscratch, (int)bytecode());
2171   __ beq(CCR0, Lresolved);
2172 
2173   address entry = NULL;
2174   switch (bytecode()) {
2175     case Bytecodes::_getstatic      : // fall through
2176     case Bytecodes::_putstatic      : // fall through
2177     case Bytecodes::_getfield       : // fall through
2178     case Bytecodes::_putfield       : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
2179     case Bytecodes::_invokevirtual  : // fall through
2180     case Bytecodes::_invokespecial  : // fall through
2181     case Bytecodes::_invokestatic   : // fall through
2182     case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break;
2183     case Bytecodes::_invokehandle   : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle); break;
2184     case Bytecodes::_invokedynamic  : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break;
2185     default                         : ShouldNotReachHere(); break;
2186   }
2187   __ li(R4_ARG2, (int)bytecode());
2188   __ call_VM(noreg, entry, R4_ARG2, true);