changeset 2374:8012aa3ccede

4926272: methodOopDesc::method_from_bcp is unsafe Reviewed-by: coleenp, jrose, kvn, dcubed
author never
date Thu, 13 Jan 2011 22:15:41 -0800
parents 34d64ad817f4
children 17c778814856
files src/share/vm/c1/c1_GraphBuilder.cpp src/share/vm/c1/c1_Runtime1.cpp src/share/vm/ci/bcEscapeAnalyzer.cpp src/share/vm/ci/ciMethod.hpp src/share/vm/ci/ciMethodBlocks.cpp src/share/vm/ci/ciStreams.hpp src/share/vm/ci/ciTypeFlow.cpp src/share/vm/code/nmethod.cpp src/share/vm/compiler/methodLiveness.cpp src/share/vm/interpreter/bytecode.cpp src/share/vm/interpreter/bytecode.hpp src/share/vm/interpreter/bytecodeInterpreter.cpp src/share/vm/interpreter/bytecodeStream.cpp src/share/vm/interpreter/bytecodeStream.hpp src/share/vm/interpreter/bytecodeTracer.cpp src/share/vm/interpreter/bytecodes.cpp src/share/vm/interpreter/bytecodes.hpp src/share/vm/interpreter/interpreter.cpp src/share/vm/interpreter/interpreterRuntime.cpp src/share/vm/interpreter/interpreterRuntime.hpp src/share/vm/interpreter/rewriter.cpp src/share/vm/interpreter/templateInterpreter.cpp src/share/vm/oops/generateOopMap.cpp src/share/vm/oops/methodDataOop.cpp src/share/vm/oops/methodOop.cpp src/share/vm/oops/methodOop.hpp src/share/vm/prims/jvmtiRedefineClasses.cpp src/share/vm/prims/methodComparator.cpp src/share/vm/runtime/deoptimization.cpp src/share/vm/runtime/frame.cpp src/share/vm/runtime/relocator.hpp src/share/vm/runtime/sharedRuntime.cpp src/share/vm/runtime/vframeArray.cpp
diffstat 33 files changed, 396 insertions(+), 496 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/c1/c1_GraphBuilder.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -319,24 +319,24 @@
 
       case Bytecodes::_tableswitch: {
         // set block for each case
-        Bytecode_tableswitch *switch_ = Bytecode_tableswitch_at(s.cur_bcp());
-        int l = switch_->length();
+        Bytecode_tableswitch sw(&s);
+        int l = sw.length();
         for (int i = 0; i < l; i++) {
-          make_block_at(cur_bci + switch_->dest_offset_at(i), current);
+          make_block_at(cur_bci + sw.dest_offset_at(i), current);
         }
-        make_block_at(cur_bci + switch_->default_offset(), current);
+        make_block_at(cur_bci + sw.default_offset(), current);
         current = NULL;
         break;
       }
 
       case Bytecodes::_lookupswitch: {
         // set block for each case
-        Bytecode_lookupswitch *switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
-        int l = switch_->number_of_pairs();
+        Bytecode_lookupswitch sw(&s);
+        int l = sw.number_of_pairs();
         for (int i = 0; i < l; i++) {
-          make_block_at(cur_bci + switch_->pair_at(i)->offset(), current);
+          make_block_at(cur_bci + sw.pair_at(i).offset(), current);
         }
-        make_block_at(cur_bci + switch_->default_offset(), current);
+        make_block_at(cur_bci + sw.default_offset(), current);
         current = NULL;
         break;
       }
@@ -1275,15 +1275,15 @@
 
 
 void GraphBuilder::table_switch() {
-  Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(method()->code() + bci());
-  const int l = switch_->length();
+  Bytecode_tableswitch sw(stream());
+  const int l = sw.length();
   if (CanonicalizeNodes && l == 1) {
     // total of 2 successors => use If instead of switch
     // Note: This code should go into the canonicalizer as soon as it can
     //       can handle canonicalized forms that contain more than one node.
-    Value key = append(new Constant(new IntConstant(switch_->low_key())));
-    BlockBegin* tsux = block_at(bci() + switch_->dest_offset_at(0));
-    BlockBegin* fsux = block_at(bci() + switch_->default_offset());
+    Value key = append(new Constant(new IntConstant(sw.low_key())));
+    BlockBegin* tsux = block_at(bci() + sw.dest_offset_at(0));
+    BlockBegin* fsux = block_at(bci() + sw.default_offset());
     bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
     ValueStack* state_before = is_bb ? copy_state_before() : NULL;
     append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
@@ -1293,29 +1293,29 @@
     int i;
     bool has_bb = false;
     for (i = 0; i < l; i++) {
-      sux->at_put(i, block_at(bci() + switch_->dest_offset_at(i)));
-      if (switch_->dest_offset_at(i) < 0) has_bb = true;
+      sux->at_put(i, block_at(bci() + sw.dest_offset_at(i)));
+      if (sw.dest_offset_at(i) < 0) has_bb = true;
     }
     // add default successor
-    sux->at_put(i, block_at(bci() + switch_->default_offset()));
+    sux->at_put(i, block_at(bci() + sw.default_offset()));
     ValueStack* state_before = has_bb ? copy_state_before() : NULL;
-    append(new TableSwitch(ipop(), sux, switch_->low_key(), state_before, has_bb));
+    append(new TableSwitch(ipop(), sux, sw.low_key(), state_before, has_bb));
   }
 }
 
 
 void GraphBuilder::lookup_switch() {
-  Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(method()->code() + bci());
-  const int l = switch_->number_of_pairs();
+  Bytecode_lookupswitch sw(stream());
+  const int l = sw.number_of_pairs();
   if (CanonicalizeNodes && l == 1) {
     // total of 2 successors => use If instead of switch
     // Note: This code should go into the canonicalizer as soon as it can
     //       can handle canonicalized forms that contain more than one node.
     // simplify to If
-    LookupswitchPair* pair = switch_->pair_at(0);
-    Value key = append(new Constant(new IntConstant(pair->match())));
-    BlockBegin* tsux = block_at(bci() + pair->offset());
-    BlockBegin* fsux = block_at(bci() + switch_->default_offset());
+    LookupswitchPair pair = sw.pair_at(0);
+    Value key = append(new Constant(new IntConstant(pair.match())));
+    BlockBegin* tsux = block_at(bci() + pair.offset());
+    BlockBegin* fsux = block_at(bci() + sw.default_offset());
     bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
     ValueStack* state_before = is_bb ? copy_state_before() : NULL;
     append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
@@ -1326,13 +1326,13 @@
     int i;
     bool has_bb = false;
     for (i = 0; i < l; i++) {
-      LookupswitchPair* pair = switch_->pair_at(i);
-      if (pair->offset() < 0) has_bb = true;
-      sux->at_put(i, block_at(bci() + pair->offset()));
-      keys->at_put(i, pair->match());
+      LookupswitchPair pair = sw.pair_at(i);
+      if (pair.offset() < 0) has_bb = true;
+      sux->at_put(i, block_at(bci() + pair.offset()));
+      keys->at_put(i, pair.match());
     }
     // add default successor
-    sux->at_put(i, block_at(bci() + switch_->default_offset()));
+    sux->at_put(i, block_at(bci() + sw.default_offset()));
     ValueStack* state_before = has_bb ? copy_state_before() : NULL;
     append(new LookupSwitch(ipop(), sux, keys, state_before, has_bb));
   }
--- a/src/share/vm/c1/c1_Runtime1.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/c1/c1_Runtime1.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -369,7 +369,7 @@
   if (branch_bci != InvocationEntryBci) {
     // Compute desination bci
     address pc = method()->code_base() + branch_bci;
-    Bytecodes::Code branch = Bytecodes::code_at(pc, method());
+    Bytecodes::Code branch = Bytecodes::code_at(method(), pc);
     int offset = 0;
     switch (branch) {
       case Bytecodes::_if_icmplt: case Bytecodes::_iflt:
@@ -659,14 +659,14 @@
 
 
 static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
-  Bytecode_field* field_access = Bytecode_field_at(caller, bci);
+  Bytecode_field field_access(caller, bci);
   // This can be static or non-static field access
-  Bytecodes::Code code       = field_access->code();
+  Bytecodes::Code code       = field_access.code();
 
   // We must load class, initialize class and resolvethe field
   FieldAccessInfo result; // initialize class if needed
   constantPoolHandle constants(THREAD, caller->constants());
-  LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK_NULL);
+  LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK_NULL);
   return result.klass()();
 }
 
@@ -767,7 +767,7 @@
 
   Events::log("patch_code @ " INTPTR_FORMAT , caller_frame.pc());
 
-  Bytecodes::Code code = Bytecode_at(caller_method->bcp_from(bci))->java_code();
+  Bytecodes::Code code = caller_method()->java_code_at(bci);
 
 #ifndef PRODUCT
   // this is used by assertions in the access_field_patching_id
@@ -779,11 +779,11 @@
   Handle load_klass(THREAD, NULL);                // oop needed by load_klass_patching code
   if (stub_id == Runtime1::access_field_patching_id) {
 
-    Bytecode_field* field_access = Bytecode_field_at(caller_method, bci);
+    Bytecode_field field_access(caller_method, bci);
     FieldAccessInfo result; // initialize class if needed
-    Bytecodes::Code code = field_access->code();
+    Bytecodes::Code code = field_access.code();
     constantPoolHandle constants(THREAD, caller_method->constants());
-    LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK);
+    LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK);
     patch_field_offset = result.field_offset();
 
     // If we're patching a field which is volatile then at compile it
@@ -811,36 +811,36 @@
         }
         break;
       case Bytecodes::_new:
-        { Bytecode_new* bnew = Bytecode_new_at(caller_method->bcp_from(bci));
-          k = caller_method->constants()->klass_at(bnew->index(), CHECK);
+        { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
+          k = caller_method->constants()->klass_at(bnew.index(), CHECK);
         }
         break;
       case Bytecodes::_multianewarray:
-        { Bytecode_multianewarray* mna = Bytecode_multianewarray_at(caller_method->bcp_from(bci));
-          k = caller_method->constants()->klass_at(mna->index(), CHECK);
+        { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
+          k = caller_method->constants()->klass_at(mna.index(), CHECK);
         }
         break;
       case Bytecodes::_instanceof:
-        { Bytecode_instanceof* io = Bytecode_instanceof_at(caller_method->bcp_from(bci));
-          k = caller_method->constants()->klass_at(io->index(), CHECK);
+        { Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci));
+          k = caller_method->constants()->klass_at(io.index(), CHECK);
         }
         break;
       case Bytecodes::_checkcast:
-        { Bytecode_checkcast* cc = Bytecode_checkcast_at(caller_method->bcp_from(bci));
-          k = caller_method->constants()->klass_at(cc->index(), CHECK);
+        { Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci));
+          k = caller_method->constants()->klass_at(cc.index(), CHECK);
         }
         break;
       case Bytecodes::_anewarray:
-        { Bytecode_anewarray* anew = Bytecode_anewarray_at(caller_method->bcp_from(bci));
-          klassOop ek = caller_method->constants()->klass_at(anew->index(), CHECK);
+        { Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci));
+          klassOop ek = caller_method->constants()->klass_at(anew.index(), CHECK);
           k = Klass::cast(ek)->array_klass(CHECK);
         }
         break;
       case Bytecodes::_ldc:
       case Bytecodes::_ldc_w:
         {
-          Bytecode_loadconstant* cc = Bytecode_loadconstant_at(caller_method, bci);
-          k = cc->resolve_constant(CHECK);
+          Bytecode_loadconstant cc(caller_method, bci);
+          k = cc.resolve_constant(CHECK);
           assert(k != NULL && !k->is_klass(), "must be class mirror or other Java constant");
         }
         break;
--- a/src/share/vm/ci/bcEscapeAnalyzer.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/ci/bcEscapeAnalyzer.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -761,15 +761,15 @@
       case Bytecodes::_tableswitch:
         {
           state.spop();
-          Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(s.cur_bcp());
-          int len = switch_->length();
+          Bytecode_tableswitch sw(&s);
+          int len = sw.length();
           int dest_bci;
           for (int i = 0; i < len; i++) {
-            dest_bci = s.cur_bci() + switch_->dest_offset_at(i);
+            dest_bci = s.cur_bci() + sw.dest_offset_at(i);
             assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
             successors.push(_methodBlocks->block_containing(dest_bci));
           }
-          dest_bci = s.cur_bci() + switch_->default_offset();
+          dest_bci = s.cur_bci() + sw.default_offset();
           assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
           successors.push(_methodBlocks->block_containing(dest_bci));
           assert(s.next_bci() == limit_bci, "branch must end block");
@@ -779,15 +779,15 @@
       case Bytecodes::_lookupswitch:
         {
           state.spop();
-          Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
-          int len = switch_->number_of_pairs();
+          Bytecode_lookupswitch sw(&s);
+          int len = sw.number_of_pairs();
           int dest_bci;
           for (int i = 0; i < len; i++) {
-            dest_bci = s.cur_bci() + switch_->pair_at(i)->offset();
+            dest_bci = s.cur_bci() + sw.pair_at(i).offset();
             assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
             successors.push(_methodBlocks->block_containing(dest_bci));
           }
-          dest_bci = s.cur_bci() + switch_->default_offset();
+          dest_bci = s.cur_bci() + sw.default_offset();
           assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
           successors.push(_methodBlocks->block_containing(dest_bci));
           fall_through = false;
--- a/src/share/vm/ci/ciMethod.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/ci/ciMethod.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -144,7 +144,7 @@
 
   Bytecodes::Code java_code_at_bci(int bci) {
     address bcp = code() + bci;
-    return Bytecodes::java_code_at(bcp);
+    return Bytecodes::java_code_at(NULL, bcp);
   }
   BCEscapeAnalyzer  *get_bcea();
   ciMethodBlocks    *get_method_blocks();
--- a/src/share/vm/ci/ciMethodBlocks.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/ci/ciMethodBlocks.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -175,15 +175,15 @@
       case Bytecodes::_tableswitch :
         {
           cur_block->set_control_bci(bci);
-          Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(s.cur_bcp());
-          int len = switch_->length();
+          Bytecode_tableswitch sw(&s);
+          int len = sw.length();
           ciBlock *dest;
           int dest_bci;
           for (int i = 0; i < len; i++) {
-            dest_bci = s.cur_bci() + switch_->dest_offset_at(i);
+            dest_bci = s.cur_bci() + sw.dest_offset_at(i);
             dest = make_block_at(dest_bci);
           }
-          dest_bci = s.cur_bci() + switch_->default_offset();
+          dest_bci = s.cur_bci() + sw.default_offset();
           make_block_at(dest_bci);
           if (s.next_bci() < limit_bci) {
             dest = make_block_at(s.next_bci());
@@ -194,15 +194,15 @@
       case Bytecodes::_lookupswitch:
         {
           cur_block->set_control_bci(bci);
-          Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
-          int len = switch_->number_of_pairs();
+          Bytecode_lookupswitch sw(&s);
+          int len = sw.number_of_pairs();
           ciBlock *dest;
           int dest_bci;
           for (int i = 0; i < len; i++) {
-            dest_bci = s.cur_bci() + switch_->pair_at(i)->offset();
+            dest_bci = s.cur_bci() + sw.pair_at(i).offset();
             dest = make_block_at(dest_bci);
           }
-          dest_bci = s.cur_bci() + switch_->default_offset();
+          dest_bci = s.cur_bci() + sw.default_offset();
           dest = make_block_at(dest_bci);
           if (s.next_bci() < limit_bci) {
             dest = make_block_at(s.next_bci());
--- a/src/share/vm/ci/ciStreams.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/ci/ciStreams.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -78,8 +78,8 @@
     else { assert(!is_wide(), "must not be a wide instruction"); }
   }
 
-  Bytecode* bytecode() const { return Bytecode_at(_bc_start); }
-  Bytecode* next_bytecode() const { return Bytecode_at(_pc); }
+  Bytecode bytecode() const { return Bytecode(this, _bc_start); }
+  Bytecode next_bytecode() const { return Bytecode(this, _pc); }
 
 public:
   // End-Of-Bytecodes
@@ -151,11 +151,11 @@
   bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
 
   int get_index_u1() const {
-    return bytecode()->get_index_u1(cur_bc_raw());
+    return bytecode().get_index_u1(cur_bc_raw());
   }
 
   int get_index_u1_cpcache() const {
-    return bytecode()->get_index_u1_cpcache(cur_bc_raw());
+    return bytecode().get_index_u1_cpcache(cur_bc_raw());
   }
 
   // Get a byte index following this bytecode.
@@ -169,29 +169,29 @@
 
   // Get 2-byte index (byte swapping depending on which bytecode)
   int get_index_u2(bool is_wide = false) const {
-    return bytecode()->get_index_u2(cur_bc_raw(), is_wide);
+    return bytecode().get_index_u2(cur_bc_raw(), is_wide);
   }
 
   // Get 2-byte index in native byte order.  (Rewriter::rewrite makes these.)
   int get_index_u2_cpcache() const {
-    return bytecode()->get_index_u2_cpcache(cur_bc_raw());
+    return bytecode().get_index_u2_cpcache(cur_bc_raw());
   }
 
   // Get 4-byte index, for invokedynamic.
   int get_index_u4() const {
-    return bytecode()->get_index_u4(cur_bc_raw());
+    return bytecode().get_index_u4(cur_bc_raw());
   }
 
   bool has_index_u4() const {
-    return bytecode()->has_index_u4(cur_bc_raw());
+    return bytecode().has_index_u4(cur_bc_raw());
   }
 
   // Get dimensions byte (multinewarray)
   int get_dimensions() const { return *(unsigned char*)(_pc-1); }
 
   // Sign-extended index byte/short, no widening
-  int get_constant_u1()                     const { return bytecode()->get_constant_u1(instruction_size()-1, cur_bc_raw()); }
-  int get_constant_u2(bool is_wide = false) const { return bytecode()->get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
+  int get_constant_u1()                     const { return bytecode().get_constant_u1(instruction_size()-1, cur_bc_raw()); }
+  int get_constant_u2(bool is_wide = false) const { return bytecode().get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
 
   // Get a byte signed constant for "iinc".  Invalid for other bytecodes.
   // If prefixed with a wide bytecode, get a wide constant
@@ -199,18 +199,18 @@
 
   // 2-byte branch offset from current pc
   int get_dest() const {
-    return cur_bci() + bytecode()->get_offset_s2(cur_bc_raw());
+    return cur_bci() + bytecode().get_offset_s2(cur_bc_raw());
   }
 
   // 2-byte branch offset from next pc
   int next_get_dest() const {
     assert(_pc < _end, "");
-    return next_bci() + next_bytecode()->get_offset_s2(Bytecodes::_ifeq);
+    return next_bci() + next_bytecode().get_offset_s2(Bytecodes::_ifeq);
   }
 
   // 4-byte branch offset from current pc
   int get_far_dest() const {
-    return cur_bci() + bytecode()->get_offset_s4(cur_bc_raw());
+    return cur_bci() + bytecode().get_offset_s4(cur_bc_raw());
   }
 
   // For a lookup or switch table, return target destination
@@ -407,4 +407,11 @@
   }
 };
 
+
+
+// Implementation for declarations in bytecode.hpp
+Bytecode::Bytecode(const ciBytecodeStream* stream, address bcp): _bcp(bcp != NULL ? bcp : stream->cur_bcp()), _code(Bytecodes::code_at(NULL, addr_at(0))) {}
+Bytecode_lookupswitch::Bytecode_lookupswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
+Bytecode_tableswitch::Bytecode_tableswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
+
 #endif // SHARE_VM_CI_CISTREAMS_HPP
--- a/src/share/vm/ci/ciTypeFlow.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/ci/ciTypeFlow.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1698,18 +1698,17 @@
         break;
 
       case Bytecodes::_tableswitch:  {
-        Bytecode_tableswitch *tableswitch =
-          Bytecode_tableswitch_at(str->cur_bcp());
+        Bytecode_tableswitch tableswitch(str);
 
-        int len = tableswitch->length();
+        int len = tableswitch.length();
         _successors =
           new (arena) GrowableArray<Block*>(arena, len+1, 0, NULL);
-        int bci = current_bci + tableswitch->default_offset();
+        int bci = current_bci + tableswitch.default_offset();
         Block* block = analyzer->block_at(bci, jsrs);
         assert(_successors->length() == SWITCH_DEFAULT, "");
         _successors->append(block);
         while (--len >= 0) {
-          int bci = current_bci + tableswitch->dest_offset_at(len);
+          int bci = current_bci + tableswitch.dest_offset_at(len);
           block = analyzer->block_at(bci, jsrs);
           assert(_successors->length() >= SWITCH_CASES, "");
           _successors->append_if_missing(block);
@@ -1718,19 +1717,18 @@
       }
 
       case Bytecodes::_lookupswitch: {
-        Bytecode_lookupswitch *lookupswitch =
-          Bytecode_lookupswitch_at(str->cur_bcp());
+        Bytecode_lookupswitch lookupswitch(str);
 
-        int npairs = lookupswitch->number_of_pairs();
+        int npairs = lookupswitch.number_of_pairs();
         _successors =
           new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
-        int bci = current_bci + lookupswitch->default_offset();
+        int bci = current_bci + lookupswitch.default_offset();
         Block* block = analyzer->block_at(bci, jsrs);
         assert(_successors->length() == SWITCH_DEFAULT, "");
         _successors->append(block);
         while(--npairs >= 0) {
-          LookupswitchPair *pair = lookupswitch->pair_at(npairs);
-          int bci = current_bci + pair->offset();
+          LookupswitchPair pair = lookupswitch.pair_at(npairs);
+          int bci = current_bci + pair.offset();
           Block* block = analyzer->block_at(bci, jsrs);
           assert(_successors->length() >= SWITCH_CASES, "");
           _successors->append_if_missing(block);
--- a/src/share/vm/code/nmethod.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/code/nmethod.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1863,9 +1863,9 @@
 #ifndef SHARK
   if (!method()->is_native()) {
     SimpleScopeDesc ssd(this, fr.pc());
-    Bytecode_invoke* call = Bytecode_invoke_at(ssd.method(), ssd.bci());
-    bool has_receiver = call->has_receiver();
-    symbolOop signature = call->signature();
+    Bytecode_invoke call(ssd.method(), ssd.bci());
+    bool has_receiver = call.has_receiver();
+    symbolOop signature = call.signature();
     fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f);
   }
 #endif // !SHARK
@@ -2698,8 +2698,7 @@
       } else if (sd->method()->is_native()) {
         st->print("method is native");
       } else {
-        address bcp  = sd->method()->bcp_from(sd->bci());
-        Bytecodes::Code bc = Bytecodes::java_code_at(bcp);
+        Bytecodes::Code bc = sd->method()->java_code_at(sd->bci());
         st->print(";*%s", Bytecodes::name(bc));
         switch (bc) {
         case Bytecodes::_invokevirtual:
@@ -2707,10 +2706,10 @@
         case Bytecodes::_invokestatic:
         case Bytecodes::_invokeinterface:
           {
-            Bytecode_invoke* invoke = Bytecode_invoke_at(sd->method(), sd->bci());
+            Bytecode_invoke invoke(sd->method(), sd->bci());
             st->print(" ");
-            if (invoke->name() != NULL)
-              invoke->name()->print_symbol_on(st);
+            if (invoke.name() != NULL)
+              invoke.name()->print_symbol_on(st);
             else
               st->print("<UNKNOWN>");
             break;
@@ -2720,10 +2719,10 @@
         case Bytecodes::_getstatic:
         case Bytecodes::_putstatic:
           {
-            Bytecode_field* field = Bytecode_field_at(sd->method(), sd->bci());
+            Bytecode_field field(sd->method(), sd->bci());
             st->print(" ");
-            if (field->name() != NULL)
-              field->name()->print_symbol_on(st);
+            if (field.name() != NULL)
+              field.name()->print_symbol_on(st);
             else
               st->print("<UNKNOWN>");
           }
--- a/src/share/vm/compiler/methodLiveness.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/compiler/methodLiveness.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -286,16 +286,15 @@
         break;
       case Bytecodes::_tableswitch:
         {
-          Bytecode_tableswitch *tableswitch =
-            Bytecode_tableswitch_at(bytes.cur_bcp());
+          Bytecode_tableswitch tableswitch(&bytes);
 
-          int len = tableswitch->length();
+          int len = tableswitch.length();
 
-          dest = _block_map->at(bci + tableswitch->default_offset());
+          dest = _block_map->at(bci + tableswitch.default_offset());
           assert(dest != NULL, "branch desination must start a block.");
           dest->add_normal_predecessor(current_block);
           while (--len >= 0) {
-            dest = _block_map->at(bci + tableswitch->dest_offset_at(len));
+            dest = _block_map->at(bci + tableswitch.dest_offset_at(len));
             assert(dest != NULL, "branch desination must start a block.");
             dest->add_normal_predecessor(current_block);
           }
@@ -304,17 +303,16 @@
 
       case Bytecodes::_lookupswitch:
         {
-          Bytecode_lookupswitch *lookupswitch =
-            Bytecode_lookupswitch_at(bytes.cur_bcp());
+          Bytecode_lookupswitch lookupswitch(&bytes);
 
-          int npairs = lookupswitch->number_of_pairs();
+          int npairs = lookupswitch.number_of_pairs();
 
-          dest = _block_map->at(bci + lookupswitch->default_offset());
+          dest = _block_map->at(bci + lookupswitch.default_offset());
           assert(dest != NULL, "branch desination must start a block.");
           dest->add_normal_predecessor(current_block);
           while(--npairs >= 0) {
-            LookupswitchPair *pair = lookupswitch->pair_at(npairs);
-            dest = _block_map->at( bci + pair->offset());
+            LookupswitchPair pair = lookupswitch.pair_at(npairs);
+            dest = _block_map->at( bci + pair.offset());
             assert(dest != NULL, "branch desination must start a block.");
             dest->add_normal_predecessor(current_block);
           }
--- a/src/share/vm/interpreter/bytecode.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecode.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,30 +34,6 @@
 
 // Implementation of Bytecode
 
-bool Bytecode::check_must_rewrite(Bytecodes::Code code) const {
-  assert(Bytecodes::can_rewrite(code), "post-check only");
-
-  // Some codes are conditionally rewriting.  Look closely at them.
-  switch (code) {
-  case Bytecodes::_aload_0:
-    // Even if RewriteFrequentPairs is turned on,
-    // the _aload_0 code might delay its rewrite until
-    // a following _getfield rewrites itself.
-    return false;
-
-  case Bytecodes::_lookupswitch:
-    return false;  // the rewrite is not done by the interpreter
-
-  case Bytecodes::_new:
-    // (Could actually look at the class here, but the profit would be small.)
-    return false;  // the rewrite is not always done
-  }
-
-  // No other special cases.
-  return true;
-}
-
-
 #ifdef ASSERT
 
 void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const {
@@ -188,17 +164,16 @@
   // Note:  Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4,
   // at the same time it allocates per-call-site CP cache entries.
   Bytecodes::Code rawc = code();
-  Bytecode* invoke = bytecode();
-  if (invoke->has_index_u4(rawc))
-    return invoke->get_index_u4(rawc);
+  if (has_index_u4(rawc))
+    return get_index_u4(rawc);
   else
-    return invoke->get_index_u2_cpcache(rawc);
+    return get_index_u2_cpcache(rawc);
 }
 
 int Bytecode_member_ref::pool_index() const {
   int index = this->index();
   DEBUG_ONLY({
-      if (!bytecode()->has_index_u4(code()))
+      if (!has_index_u4(code()))
         index -= constantPoolOopDesc::CPCACHE_INDEX_TAG;
     });
   return _method->constants()->cache()->entry_at(index)->constant_pool_index();
@@ -214,13 +189,12 @@
 // Implementation of Bytecode_loadconstant
 
 int Bytecode_loadconstant::raw_index() const {
-  Bytecode* bcp = bytecode();
-  Bytecodes::Code rawc = bcp->code();
+  Bytecodes::Code rawc = code();
   assert(rawc != Bytecodes::_wide, "verifier prevents this");
   if (Bytecodes::java_code(rawc) == Bytecodes::_ldc)
-    return bcp->get_index_u1(rawc);
+    return get_index_u1(rawc);
   else
-    return bcp->get_index_u2(rawc, false);
+    return get_index_u2(rawc, false);
 }
 
 int Bytecode_loadconstant::pool_index() const {
@@ -258,7 +232,7 @@
     case Bytecodes::_lookupswitch:
       { int i = number_of_pairs() - 1;
         while (i-- > 0) {
-          assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries");
+          assert(pair_at(i).match() < pair_at(i+1).match(), "unsorted table entries");
         }
       }
       break;
--- a/src/share/vm/interpreter/bytecode.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecode.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,14 +38,20 @@
 # include "bytes_zero.hpp"
 #endif
 
-// Base class for different kinds of abstractions working
-// relative to an objects 'this' pointer.
+class ciBytecodeStream;
 
-class ThisRelativeObj VALUE_OBJ_CLASS_SPEC {
- public:
+// The base class for different kinds of bytecode abstractions.
+// Provides the primitive operations to manipulate code relative
+// to the bcp.
+
+class Bytecode: public StackObj {
+ protected:
+  const address   _bcp;
+  const Bytecodes::Code _code;
+
   // Address computation
-  address addr_at            (int offset)        const     { return (address)this + offset; }
-  int     byte_at            (int offset)        const     { return *(addr_at(offset)); }
+  address addr_at            (int offset)        const     { return (address)_bcp + offset; }
+  u_char byte_at(int offset) const               { return *addr_at(offset); }
   address aligned_addr_at    (int offset)        const     { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
   int     aligned_offset     (int offset)        const     { return aligned_addr_at(offset) - addr_at(0); }
 
@@ -54,31 +60,20 @@
   int     get_Java_u4_at     (int offset)        const     { return Bytes::get_Java_u4(addr_at(offset)); }
   int     get_native_u2_at   (int offset)        const     { return Bytes::get_native_u2(addr_at(offset)); }
   int     get_native_u4_at   (int offset)        const     { return Bytes::get_native_u4(addr_at(offset)); }
-};
-
-
-// The base class for different kinds of bytecode abstractions.
-// Provides the primitive operations to manipulate code relative
-// to an objects 'this' pointer.
-// FIXME: Make this a ResourceObj, include the enclosing methodOop, and cache the opcode.
-
-class Bytecode: public ThisRelativeObj {
- protected:
-  u_char byte_at(int offset) const               { return *addr_at(offset); }
-  bool check_must_rewrite(Bytecodes::Code bc) const;
 
  public:
+  Bytecode(methodOop method, address bcp): _bcp(bcp), _code(Bytecodes::code_at(method, addr_at(0))) {
+    assert(method != NULL, "this form requires a valid methodOop");
+  }
+  // Defined in ciStreams.hpp
+  inline Bytecode(const ciBytecodeStream* stream, address bcp = NULL);
+
   // Attributes
-  address bcp() const                            { return addr_at(0); }
-  int instruction_size() const                   { return Bytecodes::length_at(bcp()); }
+  address bcp() const                            { return _bcp; }
+  int instruction_size() const                   { return Bytecodes::length_for_code_at(_code, bcp()); }
 
-  // Warning: Use code() with caution on live bytecode streams.  4926272
-  Bytecodes::Code code() const                   { return Bytecodes::code_at(addr_at(0)); }
+  Bytecodes::Code code() const                   { return _code; }
   Bytecodes::Code java_code() const              { return Bytecodes::java_code(code()); }
-  bool must_rewrite(Bytecodes::Code code) const  { return Bytecodes::can_rewrite(code) && check_must_rewrite(code); }
-
-  // Creation
-  inline friend Bytecode* Bytecode_at(address bcp);
 
   // Static functions for parsing bytecodes in place.
   int get_index_u1(Bytecodes::Code bc) const {
@@ -89,7 +84,7 @@
     assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide);
     address p = addr_at(is_wide ? 2 : 1);
     if (can_use_native_byte_order(bc, is_wide))
-          return Bytes::get_native_u2(p);
+      return Bytes::get_native_u2(p);
     else  return Bytes::get_Java_u2(p);
   }
   int get_index_u1_cpcache(Bytecodes::Code bc) const {
@@ -138,20 +133,17 @@
   }
 };
 
-inline Bytecode* Bytecode_at(address bcp) {
-  // Warning: Use with caution on live bytecode streams.  4926272
-  return (Bytecode*)bcp;
-}
-
 
 // Abstractions for lookupswitch bytecode
+class LookupswitchPair VALUE_OBJ_CLASS_SPEC {
+ private:
+  const address _bcp;
 
-class LookupswitchPair: ThisRelativeObj {
- private:
-  int  _match;
-  int  _offset;
+  address addr_at            (int offset)        const     { return _bcp + offset; }
+  int     get_Java_u4_at     (int offset)        const     { return Bytes::get_Java_u4(addr_at(offset)); }
 
  public:
+  LookupswitchPair(address bcp): _bcp(bcp) {}
   int  match() const                             { return get_Java_u4_at(0 * jintSize); }
   int  offset() const                            { return get_Java_u4_at(1 * jintSize); }
 };
@@ -159,26 +151,25 @@
 
 class Bytecode_lookupswitch: public Bytecode {
  public:
+  Bytecode_lookupswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
+  // Defined in ciStreams.hpp
+  inline Bytecode_lookupswitch(const ciBytecodeStream* stream);
   void verify() const PRODUCT_RETURN;
 
   // Attributes
   int  default_offset() const                    { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
   int  number_of_pairs() const                   { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
-  LookupswitchPair* pair_at(int i) const         { assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
-                                                   return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); }
-  // Creation
-  inline friend Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp);
+  LookupswitchPair pair_at(int i) const          {
+    assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
+    return LookupswitchPair(aligned_addr_at(1 + (1 + i)*2*jintSize));
+  }
 };
 
-inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) {
-  Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 class Bytecode_tableswitch: public Bytecode {
  public:
+  Bytecode_tableswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
+  // Defined in ciStreams.hpp
+  inline Bytecode_tableswitch(const ciBytecodeStream* stream);
   void verify() const PRODUCT_RETURN;
 
   // Attributes
@@ -187,52 +178,36 @@
   int  high_key() const                          { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); }
   int  dest_offset_at(int i) const;
   int  length()                                  { return high_key()-low_key()+1; }
-
-  // Creation
-  inline friend Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp);
 };
 
-inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) {
-  Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 // Common code for decoding invokes and field references.
 
-class Bytecode_member_ref: public ResourceObj {
+class Bytecode_member_ref: public Bytecode {
  protected:
-  methodHandle _method;                          // method containing the bytecode
-  int          _bci;                             // position of the bytecode
+  const methodHandle _method;                          // method containing the bytecode
 
-  Bytecode_member_ref(methodHandle method, int bci)  : _method(method), _bci(bci) {}
+  Bytecode_member_ref(methodHandle method, int bci)  : Bytecode(method(), method()->bcp_from(bci)), _method(method) {}
+
+  methodHandle method() const                    { return _method; }
 
  public:
-  // Attributes
-  methodHandle method() const                    { return _method; }
-  int          bci() const                       { return _bci; }
-  address      bcp() const                       { return _method->bcp_from(bci()); }
-  Bytecode*    bytecode() const                  { return Bytecode_at(bcp()); }
-
   int          index() const;                    // cache index (loaded from instruction)
   int          pool_index() const;               // constant pool index
   symbolOop    name() const;                     // returns the name of the method or field
   symbolOop    signature() const;                // returns the signature of the method or field
 
   BasicType    result_type(Thread* thread) const; // returns the result type of the getfield or invoke
-
-  Bytecodes::Code code() const                   { return Bytecodes::code_at(bcp(), _method()); }
-  Bytecodes::Code java_code() const              { return Bytecodes::java_code(code()); }
 };
 
 // Abstraction for invoke_{virtual, static, interface, special}
 
 class Bytecode_invoke: public Bytecode_member_ref {
  protected:
-  Bytecode_invoke(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) {}
+  // Constructor that skips verification
+  Bytecode_invoke(methodHandle method, int bci, bool unused)  : Bytecode_member_ref(method, bci) {}
 
  public:
+  Bytecode_invoke(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) { verify(); }
   void verify() const;
 
   // Attributes
@@ -253,31 +228,20 @@
                                                           is_invokespecial()   ||
                                                           is_invokedynamic(); }
 
-  // Creation
-  inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci);
-
-  // Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke.
-  inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci);
+  // Helper to skip verification.   Used is_valid() to check if the result is really an invoke
+  inline friend Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci);
 };
 
-inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
-  Bytecode_invoke* b = new Bytecode_invoke(method, bci);
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) {
-  Bytecode_invoke* b = new Bytecode_invoke(method, bci);
-  return b->is_valid() ? b : NULL;
+inline Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci) {
+  return Bytecode_invoke(method, bci, false);
 }
 
 
 // Abstraction for all field accesses (put/get field/static)
 class Bytecode_field: public Bytecode_member_ref {
- protected:
-  Bytecode_field(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) {}
+ public:
+  Bytecode_field(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) { verify(); }
 
- public:
   // Testers
   bool is_getfield() const                       { return java_code() == Bytecodes::_getfield; }
   bool is_putfield() const                       { return java_code() == Bytecodes::_putfield; }
@@ -292,131 +256,64 @@
                                                           is_getstatic()  ||
                                                           is_putstatic(); }
   void verify() const;
-
-  // Creation
-  inline friend Bytecode_field* Bytecode_field_at(methodHandle method, int bci);
 };
 
-inline Bytecode_field* Bytecode_field_at(methodHandle method, int bci) {
-  Bytecode_field* b = new Bytecode_field(method, bci);
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 // Abstraction for checkcast
-
 class Bytecode_checkcast: public Bytecode {
  public:
+  Bytecode_checkcast(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
   void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
 
   // Returns index
   long index() const   { return get_index_u2(Bytecodes::_checkcast); };
-
-  // Creation
-  inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp);
 };
 
-inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
-  Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 // Abstraction for instanceof
-
 class Bytecode_instanceof: public Bytecode {
  public:
+  Bytecode_instanceof(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
   void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
 
   // Returns index
   long index() const   { return get_index_u2(Bytecodes::_instanceof); };
-
-  // Creation
-  inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp);
 };
 
-inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
-  Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 class Bytecode_new: public Bytecode {
  public:
+  Bytecode_new(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
   void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
 
   // Returns index
   long index() const   { return get_index_u2(Bytecodes::_new); };
-
-  // Creation
-  inline friend Bytecode_new* Bytecode_new_at(address bcp);
 };
 
-inline Bytecode_new* Bytecode_new_at(address bcp) {
-  Bytecode_new* b = (Bytecode_new*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 class Bytecode_multianewarray: public Bytecode {
  public:
+  Bytecode_multianewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
   void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
 
   // Returns index
   long index() const   { return get_index_u2(Bytecodes::_multianewarray); };
-
-  // Creation
-  inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp);
 };
 
-inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
-  Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 class Bytecode_anewarray: public Bytecode {
  public:
+  Bytecode_anewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
   void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
 
   // Returns index
   long index() const   { return get_index_u2(Bytecodes::_anewarray); };
-
-  // Creation
-  inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);
 };
 
-inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
-  Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
-
 // Abstraction for ldc, ldc_w and ldc2_w
-
-class Bytecode_loadconstant: public ResourceObj {
+class Bytecode_loadconstant: public Bytecode {
  private:
-  int          _bci;
-  methodHandle _method;
-
-  Bytecodes::Code code() const                   { return bytecode()->code(); }
+  const methodHandle _method;
 
   int raw_index() const;
 
-  Bytecode_loadconstant(methodHandle method, int bci) : _method(method), _bci(bci) {}
-
  public:
-  // Attributes
-  methodHandle method() const                    { return _method; }
-  int          bci() const                       { return _bci; }
-  address      bcp() const                       { return _method->bcp_from(bci()); }
-  Bytecode*    bytecode() const                  { return Bytecode_at(bcp()); }
+  Bytecode_loadconstant(methodHandle method, int bci): Bytecode(method(), method->bcp_from(bci)), _method(method) { verify(); }
 
   void verify() const {
     assert(_method.not_null(), "must supply method");
@@ -437,15 +334,6 @@
   BasicType result_type() const;        // returns the result type of the ldc
 
   oop resolve_constant(TRAPS) const;
-
-  // Creation
-  inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(methodHandle method, int bci);
 };
 
-inline Bytecode_loadconstant* Bytecode_loadconstant_at(methodHandle method, int bci) {
-  Bytecode_loadconstant* b = new Bytecode_loadconstant(method, bci);
-  DEBUG_ONLY(b->verify());
-  return b;
-}
-
 #endif // SHARE_VM_INTERPRETER_BYTECODE_HPP
--- a/src/share/vm/interpreter/bytecodeInterpreter.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -831,11 +831,11 @@
       // much like trying to deopt at a poll return. In that has we simply
       // get out of here
       //
-      if ( Bytecodes::code_at(pc, METHOD) == Bytecodes::_return_register_finalizer) {
+      if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
         // this will do the right thing even if an exception is pending.
         goto handle_return;
       }
-      UPDATE_PC(Bytecodes::length_at(pc));
+      UPDATE_PC(Bytecodes::length_at(METHOD, pc));
       if (THREAD->has_pending_exception()) goto handle_exception;
       goto run;
     }
--- a/src/share/vm/interpreter/bytecodeStream.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecodeStream.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -59,7 +59,7 @@
     // in raw mode, pretend indy is "bJJ__"
     assert(size == 2, "raw invokedynamic instruction has 2-byte index only");
   } else {
-    bytecode()->assert_index_size(size, raw_code(), is_wide());
+    bytecode().assert_index_size(size, raw_code(), is_wide());
   }
 }
 
--- a/src/share/vm/interpreter/bytecodeStream.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecodeStream.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -105,14 +105,14 @@
   bool            is_last_bytecode() const       { return _next_bci >= _end_bci; }
 
   address         bcp() const                    { return method()->code_base() + _bci; }
-  Bytecode*       bytecode() const               { return Bytecode_at(bcp()); }
+  Bytecode        bytecode() const               { return Bytecode(_method(), bcp()); }
 
   // State changes
   void            set_next_bci(int bci)          { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; }
 
   // Bytecode-specific attributes
-  int             dest() const                   { return bci() + bytecode()->get_offset_s2(raw_code()); }
-  int             dest_w() const                 { return bci() + bytecode()->get_offset_s4(raw_code()); }
+  int             dest() const                   { return bci() + bytecode().get_offset_s2(raw_code()); }
+  int             dest_w() const                 { return bci() + bytecode().get_offset_s4(raw_code()); }
 
   // One-byte indices.
   int             get_index_u1() const           { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); }
@@ -189,7 +189,7 @@
     } else {
       // get bytecode
       address bcp = this->bcp();
-      raw_code = Bytecodes::code_at(bcp);
+      raw_code = Bytecodes::code_at(_method(), bcp);
       code = Bytecodes::java_code(raw_code);
       // set next bytecode position
       //
@@ -197,7 +197,7 @@
       // tty bytecode otherwise the stepping is wrong!
       // (carefull: length_for(...) must be used first!)
       int l = Bytecodes::length_for(code);
-      if (l == 0) l = Bytecodes::length_at(bcp);
+      if (l == 0) l = Bytecodes::length_at(_method(), bcp);
       _next_bci  += l;
       assert(_bci < _next_bci, "length must be > 0");
       // set attributes
@@ -219,16 +219,16 @@
   Bytecodes::Code code() const                   { return _code; }
 
   // Unsigned indices, widening
-  int             get_index() const              { return is_wide() ? bytecode()->get_index_u2(raw_code(), true) : get_index_u1(); }
+  int             get_index() const              { return is_wide() ? bytecode().get_index_u2(raw_code(), true) : get_index_u1(); }
   // Get an unsigned 2-byte index, swapping the bytes if necessary.
   int             get_index_u2() const           { assert_raw_stream(false);
-                                                   return bytecode()->get_index_u2(raw_code(), false); }
+                                                   return bytecode().get_index_u2(raw_code(), false); }
   // Get an unsigned 2-byte index in native order.
   int             get_index_u2_cpcache() const   { assert_raw_stream(false);
-                                                   return bytecode()->get_index_u2_cpcache(raw_code()); }
+                                                   return bytecode().get_index_u2_cpcache(raw_code()); }
   int             get_index_u4() const           { assert_raw_stream(false);
-                                                   return bytecode()->get_index_u4(raw_code()); }
-  bool            has_index_u4() const           { return bytecode()->has_index_u4(raw_code()); }
+                                                   return bytecode().get_index_u4(raw_code()); }
+  bool            has_index_u4() const           { return bytecode().has_index_u4(raw_code()); }
 };
 
 #endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP
--- a/src/share/vm/interpreter/bytecodeTracer.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecodeTracer.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -100,9 +100,9 @@
     Bytecodes::Code code;
     if (is_wide()) {
       // bcp wasn't advanced if previous bytecode was _wide.
-      code = Bytecodes::code_at(bcp+1);
+      code = Bytecodes::code_at(method(), bcp+1);
     } else {
-      code = Bytecodes::code_at(bcp);
+      code = Bytecodes::code_at(method(), bcp);
     }
     _code = code;
      int bci = bcp - method->code_base();
@@ -127,11 +127,11 @@
   void trace(methodHandle method, address bcp, outputStream* st) {
     _current_method = method();
     ResourceMark rm;
-    Bytecodes::Code code = Bytecodes::code_at(bcp);
+    Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
     // Set is_wide
     _is_wide = (code == Bytecodes::_wide);
     if (is_wide()) {
-      code = Bytecodes::code_at(bcp+1);
+      code = Bytecodes::code_at(method(), bcp+1);
     }
     _code = code;
     int bci = bcp - method->code_base();
--- a/src/share/vm/interpreter/bytecodes.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecodes.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -54,18 +54,46 @@
 Bytecodes::Code Bytecodes::_java_code     [Bytecodes::number_of_codes];
 u_short         Bytecodes::_flags         [(1<<BitsPerByte)*2];
 
+#ifdef ASSERT
+bool Bytecodes::check_method(const methodOopDesc* method, address bcp) {
+  return method->contains(bcp);
+}
+#endif
+
+bool Bytecodes::check_must_rewrite(Bytecodes::Code code) {
+  assert(can_rewrite(code), "post-check only");
+
+  // Some codes are conditionally rewriting.  Look closely at them.
+  switch (code) {
+  case Bytecodes::_aload_0:
+    // Even if RewriteFrequentPairs is turned on,
+    // the _aload_0 code might delay its rewrite until
+    // a following _getfield rewrites itself.
+    return false;
+
+  case Bytecodes::_lookupswitch:
+    return false;  // the rewrite is not done by the interpreter
+
+  case Bytecodes::_new:
+    // (Could actually look at the class here, but the profit would be small.)
+    return false;  // the rewrite is not always done
+  }
+
+  // No other special cases.
+  return true;
+}
 
 Bytecodes::Code Bytecodes::code_at(methodOop method, int bci) {
-  return code_at(method->bcp_from(bci), method);
+  return code_at(method, method->bcp_from(bci));
 }
 
-Bytecodes::Code Bytecodes::non_breakpoint_code_at(address bcp, methodOop method) {
-  if (method == NULL)  method = methodOopDesc::method_from_bcp(bcp);
+Bytecodes::Code Bytecodes::non_breakpoint_code_at(const methodOopDesc* method, address bcp) {
+  assert(method != NULL, "must have the method for breakpoint conversion");
+  assert(method->contains(bcp), "must be valid bcp in method");
   return method->orig_bytecode_at(method->bci_from(bcp));
 }
 
-int Bytecodes::special_length_at(address bcp, address end) {
-  Code code = code_at(bcp);
+int Bytecodes::special_length_at(Bytecodes::Code code, address bcp, address end) {
   switch (code) {
   case _wide:
     if (end != NULL && bcp + 1 >= end) {
@@ -120,7 +148,7 @@
   if (code == _breakpoint) {
     return 1;
   } else {
-    return special_length_at(bcp, end);
+    return special_length_at(code, bcp, end);
   }
 }
 
--- a/src/share/vm/interpreter/bytecodes.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/bytecodes.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -342,6 +342,12 @@
   static void        pd_initialize();              // platform specific initialization
   static Code        pd_base_code_for(Code code);  // platform specific base_code_for implementation
 
+  // Verify that bcp points into method
+#ifdef ASSERT
+  static bool        check_method(const methodOopDesc* method, address bcp);
+#endif
+  static bool check_must_rewrite(Bytecodes::Code bc);
+
  public:
   // Conversion
   static void        check          (Code code)    { assert(is_defined(code), "illegal code"); }
@@ -349,22 +355,30 @@
   static Code        cast           (int  code)    { return (Code)code; }
 
 
-   // Fetch a bytecode, hiding breakpoints as necessary:
-   static Code       code_at(address bcp, methodOop method = NULL) {
-          Code code = cast(*bcp); return (code != _breakpoint) ? code : non_breakpoint_code_at(bcp, method);
-   }
-   static Code       java_code_at(address bcp, methodOop method = NULL) {
-          return java_code(code_at(bcp, method));
-   }
+  // Fetch a bytecode, hiding breakpoints as necessary.  The method
+  // argument is used for conversion of breakpoints into the original
+  // bytecode.  The CI uses these methods but guarantees that
+  // breakpoints are hidden so the method argument should be passed as
+  // NULL since in that case the bcp and methodOop are unrelated
+  // memory.
+  static Code       code_at(const methodOopDesc* method, address bcp) {
+    assert(method == NULL || check_method(method, bcp), "bcp must point into method");
+    Code code = cast(*bcp);
+    assert(code != _breakpoint || method != NULL, "need methodOop to decode breakpoint");
+    return (code != _breakpoint) ? code : non_breakpoint_code_at(method, bcp);
+  }
+  static Code       java_code_at(const methodOopDesc* method, address bcp) {
+    return java_code(code_at(method, bcp));
+  }
 
-   // Fetch a bytecode or a breakpoint:
-   static Code       code_or_bp_at(address bcp)    { return (Code)cast(*bcp); }
+  // Fetch a bytecode or a breakpoint:
+  static Code       code_or_bp_at(address bcp)    { return (Code)cast(*bcp); }
 
-   static Code       code_at(methodOop method, int bci);
-   static bool       is_active_breakpoint_at(address bcp) { return (Code)*bcp == _breakpoint; }
+  static Code       code_at(methodOop method, int bci);
+  static bool       is_active_breakpoint_at(address bcp) { return (Code)*bcp == _breakpoint; }
 
-   // find a bytecode, behind a breakpoint if necessary:
-   static Code       non_breakpoint_code_at(address bcp, methodOop method = NULL);
+  // find a bytecode, behind a breakpoint if necessary:
+  static Code       non_breakpoint_code_at(const methodOopDesc* method, address bcp);
 
   // Bytecode attributes
   static bool        is_defined     (int  code)    { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
@@ -379,14 +393,17 @@
   static bool        can_trap       (Code code)    { check(code);      return has_all_flags(code, _bc_can_trap, false); }
   static Code        java_code      (Code code)    { check(code);      return _java_code     [code]; }
   static bool        can_rewrite    (Code code)    { check(code);      return has_all_flags(code, _bc_can_rewrite, false); }
+  static bool        must_rewrite(Bytecodes::Code code) { return can_rewrite(code) && check_must_rewrite(code); }
   static bool        native_byte_order(Code code)  { check(code);      return has_all_flags(code, _fmt_has_nbo, false); }
   static bool        uses_cp_cache  (Code code)    { check(code);      return has_all_flags(code, _fmt_has_j, false); }
   // if 'end' is provided, it indicates the end of the code buffer which
   // should not be read past when parsing.
-  static int         special_length_at(address bcp, address end = NULL);
+  static int         special_length_at(Bytecodes::Code code, address bcp, address end = NULL);
+  static int         special_length_at(methodOop method, address bcp, address end = NULL) { return special_length_at(code_at(method, bcp), bcp, end); }
   static int         raw_special_length_at(address bcp, address end = NULL);
-  static int         length_at      (address bcp)  { int l = length_for(code_at(bcp)); return l > 0 ? l : special_length_at(bcp); }
-  static int         java_length_at (address bcp)  { int l = length_for(java_code_at(bcp)); return l > 0 ? l : special_length_at(bcp); }
+  static int         length_for_code_at(Bytecodes::Code code, address bcp)  { int l = length_for(code); return l > 0 ? l : special_length_at(code, bcp); }
+  static int         length_at      (methodOop method, address bcp)  { return length_for_code_at(code_at(method, bcp), bcp); }
+  static int         java_length_at (methodOop method, address bcp)  { return length_for_code_at(java_code_at(method, bcp), bcp); }
   static bool        is_java_code   (Code code)    { return 0 <= code && code < number_of_java_codes; }
 
   static bool        is_aload       (Code code)    { return (code == _aload  || code == _aload_0  || code == _aload_1
--- a/src/share/vm/interpreter/interpreter.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/interpreter.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -237,10 +237,9 @@
 // Return true if the interpreter can prove that the given bytecode has
 // not yet been executed (in Java semantics, not in actual operation).
 bool AbstractInterpreter::is_not_reached(methodHandle method, int bci) {
-  address bcp = method->bcp_from(bci);
-  Bytecodes::Code code = Bytecodes::code_at(bcp, method());
+  Bytecodes::Code code = method()->code_at(bci);
 
-  if (!Bytecode_at(bcp)->must_rewrite(code)) {
+  if (!Bytecodes::must_rewrite(code)) {
     // might have been reached
     return false;
   }
@@ -286,12 +285,12 @@
 // If deoptimization happens, this function returns the point of next bytecode to continue execution
 address AbstractInterpreter::deopt_continue_after_entry(methodOop method, address bcp, int callee_parameters, bool is_top_frame) {
   assert(method->contains(bcp), "just checkin'");
-  Bytecodes::Code code   = Bytecodes::java_code_at(bcp);
+  Bytecodes::Code code   = Bytecodes::java_code_at(method, bcp);
   assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute");
   int             bci    = method->bci_from(bcp);
   int             length = -1; // initial value for debugging
   // compute continuation length
-  length = Bytecodes::length_at(bcp);
+  length = Bytecodes::length_at(method, bcp);
   // compute result type
   BasicType type = T_ILLEGAL;
 
@@ -303,7 +302,7 @@
       Thread *thread = Thread::current();
       ResourceMark rm(thread);
       methodHandle mh(thread, method);
-      type = Bytecode_invoke_at(mh, bci)->result_type(thread);
+      type = Bytecode_invoke(mh, bci).result_type(thread);
       // since the cache entry might not be initialized:
       // (NOT needed for the old calling convension)
       if (!is_top_frame) {
@@ -317,7 +316,7 @@
       Thread *thread = Thread::current();
       ResourceMark rm(thread);
       methodHandle mh(thread, method);
-      type = Bytecode_invoke_at(mh, bci)->result_type(thread);
+      type = Bytecode_invoke(mh, bci).result_type(thread);
       // since the cache entry might not be initialized:
       // (NOT needed for the old calling convension)
       if (!is_top_frame) {
@@ -334,7 +333,7 @@
         Thread *thread = Thread::current();
         ResourceMark rm(thread);
         methodHandle mh(thread, method);
-        type = Bytecode_loadconstant_at(mh, bci)->result_type();
+        type = Bytecode_loadconstant(mh, bci).result_type();
         break;
       }
 
@@ -356,7 +355,7 @@
 //       Interpreter::deopt_entry(vtos, 0) like others
 address AbstractInterpreter::deopt_reexecute_entry(methodOop method, address bcp) {
   assert(method->contains(bcp), "just checkin'");
-  Bytecodes::Code code   = Bytecodes::java_code_at(bcp);
+  Bytecodes::Code code   = Bytecodes::java_code_at(method, bcp);
 #ifdef COMPILER1
   if(code == Bytecodes::_athrow ) {
     return Interpreter::rethrow_exception_entry();
--- a/src/share/vm/interpreter/interpreterRuntime.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/interpreterRuntime.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -132,9 +132,9 @@
          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
   ResourceMark rm(thread);
   methodHandle m (thread, method(thread));
-  Bytecode_loadconstant* ldc = Bytecode_loadconstant_at(m, bci(thread));
-  oop result = ldc->resolve_constant(THREAD);
-  DEBUG_ONLY(ConstantPoolCacheEntry* cpce = m->constants()->cache()->entry_at(ldc->cache_index()));
+  Bytecode_loadconstant ldc(m, bci(thread));
+  oop result = ldc.resolve_constant(THREAD);
+  DEBUG_ONLY(ConstantPoolCacheEntry* cpce = m->constants()->cache()->entry_at(ldc.cache_index()));
   assert(result == cpce->f1(), "expected result for assembly code");
 }
 IRT_END
@@ -672,8 +672,8 @@
   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
     ResourceMark rm(thread);
     methodHandle m (thread, method(thread));
-    Bytecode_invoke* call = Bytecode_invoke_at(m, bci(thread));
-    symbolHandle signature (thread, call->signature());
+    Bytecode_invoke call(m, bci(thread));
+    symbolHandle signature (thread, call.signature());
     receiver = Handle(thread,
                   thread->last_frame().interpreter_callee_receiver(signature));
     assert(Universe::heap()->is_in_reserved_or_null(receiver()),
@@ -756,7 +756,7 @@
     caller_bci = caller_method->bci_from(caller_bcp);
     site_index = Bytes::get_native_u4(caller_bcp+1);
   }
-  assert(site_index == InterpreterRuntime::bytecode(thread)->get_index_u4(bytecode), "");
+  assert(site_index == InterpreterRuntime::bytecode(thread).get_index_u4(bytecode), "");
   assert(constantPoolCacheOopDesc::is_secondary_index(site_index), "proper format");
   // there is a second CPC entries that is of interest; it caches signature info:
   int main_index = pool->cache()->secondary_entry_at(site_index)->main_entry_index();
@@ -1245,9 +1245,9 @@
   assert(fr.is_interpreted_frame(), "");
   jint bci = fr.interpreter_frame_bci();
   methodHandle mh(thread, fr.interpreter_frame_method());
-  Bytecode_invoke* invoke = Bytecode_invoke_at(mh, bci);
-  ArgumentSizeComputer asc(invoke->signature());
-  int size_of_arguments = (asc.size() + (invoke->has_receiver() ? 1 : 0)); // receiver
+  Bytecode_invoke invoke(mh, bci);
+  ArgumentSizeComputer asc(invoke.signature());
+  int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
   Copy::conjoint_jbytes(src_address, dest_address,
                        size_of_arguments * Interpreter::stackElementSize);
 IRT_END
--- a/src/share/vm/interpreter/interpreterRuntime.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/interpreterRuntime.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,16 +58,16 @@
   static void      set_bcp_and_mdp(address bcp, JavaThread*thread);
   static Bytecodes::Code code(JavaThread *thread)    {
     // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)
-    return Bytecodes::code_at(bcp(thread), method(thread));
+    return Bytecodes::code_at(method(thread), bcp(thread));
   }
   static bool      already_resolved(JavaThread *thread) { return cache_entry(thread)->is_resolved(code(thread)); }
-  static Bytecode* bytecode(JavaThread *thread)      { return Bytecode_at(bcp(thread)); }
+  static Bytecode  bytecode(JavaThread *thread)      { return Bytecode(method(thread), bcp(thread)); }
   static int       get_index_u1(JavaThread *thread, Bytecodes::Code bc)
-                                                        { return bytecode(thread)->get_index_u1(bc); }
+                                                        { return bytecode(thread).get_index_u1(bc); }
   static int       get_index_u2(JavaThread *thread, Bytecodes::Code bc)
-                                                        { return bytecode(thread)->get_index_u2(bc); }
+                                                        { return bytecode(thread).get_index_u2(bc); }
   static int       get_index_u2_cpcache(JavaThread *thread, Bytecodes::Code bc)
-                                                        { return bytecode(thread)->get_index_u2_cpcache(bc); }
+                                                        { return bytecode(thread).get_index_u2_cpcache(bc); }
   static int       number_of_dimensions(JavaThread *thread)  { return bcp(thread)[3]; }
 
   static ConstantPoolCacheEntry* cache_entry_at(JavaThread *thread, int i)  { return method(thread)->constants()->cache()->entry_at(i); }
--- a/src/share/vm/interpreter/rewriter.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/rewriter.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -221,7 +221,7 @@
       // call to calculate the length.
       bc_length = Bytecodes::length_for(c);
       if (bc_length == 0) {
-        bc_length = Bytecodes::length_at(bcp);
+        bc_length = Bytecodes::length_at(method, bcp);
 
         // length_at will put us at the bytecode after the one modified
         // by 'wide'. We don't currently examine any of the bytecodes
@@ -237,9 +237,9 @@
       switch (c) {
         case Bytecodes::_lookupswitch   : {
 #ifndef CC_INTERP
-          Bytecode_lookupswitch* bc = Bytecode_lookupswitch_at(bcp);
+          Bytecode_lookupswitch bc(method, bcp);
           (*bcp) = (
-            bc->number_of_pairs() < BinarySwitchThreshold
+            bc.number_of_pairs() < BinarySwitchThreshold
             ? Bytecodes::_fast_linearswitch
             : Bytecodes::_fast_binaryswitch
           );
--- a/src/share/vm/interpreter/templateInterpreter.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/interpreter/templateInterpreter.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -592,7 +592,7 @@
 //       that do not return "Interpreter::deopt_entry(vtos, 0)"
 address TemplateInterpreter::deopt_reexecute_entry(methodOop method, address bcp) {
   assert(method->contains(bcp), "just checkin'");
-  Bytecodes::Code code   = Bytecodes::java_code_at(bcp);
+  Bytecodes::Code code   = Bytecodes::java_code_at(method, bcp);
   if (code == Bytecodes::_return) {
     // This is used for deopt during registration of finalizers
     // during Object.<init>.  We simply need to resume execution at
--- a/src/share/vm/oops/generateOopMap.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/oops/generateOopMap.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -535,23 +535,23 @@
       (*jmpFct)(this, bcs->dest_w(), data);
       break;
     case Bytecodes::_tableswitch:
-      { Bytecode_tableswitch *tableswitch = Bytecode_tableswitch_at(bcs->bcp());
-        int len = tableswitch->length();
+      { Bytecode_tableswitch tableswitch(method(), bcs->bcp());
+        int len = tableswitch.length();
 
-        (*jmpFct)(this, bci + tableswitch->default_offset(), data); /* Default. jump address */
+        (*jmpFct)(this, bci + tableswitch.default_offset(), data); /* Default. jump address */
         while (--len >= 0) {
-          (*jmpFct)(this, bci + tableswitch->dest_offset_at(len), data);
+          (*jmpFct)(this, bci + tableswitch.dest_offset_at(len), data);
         }
         break;
       }
 
     case Bytecodes::_lookupswitch:
-      { Bytecode_lookupswitch *lookupswitch = Bytecode_lookupswitch_at(bcs->bcp());
-        int npairs = lookupswitch->number_of_pairs();
-        (*jmpFct)(this, bci + lookupswitch->default_offset(), data); /* Default. */
+      { Bytecode_lookupswitch lookupswitch(method(), bcs->bcp());
+        int npairs = lookupswitch.number_of_pairs();
+        (*jmpFct)(this, bci + lookupswitch.default_offset(), data); /* Default. */
         while(--npairs >= 0) {
-          LookupswitchPair *pair = lookupswitch->pair_at(npairs);
-          (*jmpFct)(this, bci + pair->offset(), data);
+          LookupswitchPair pair = lookupswitch.pair_at(npairs);
+          (*jmpFct)(this, bci + pair.offset(), data);
         }
         break;
       }
@@ -977,7 +977,7 @@
 #ifdef ASSERT
     if (blockNum + 1 < bbNo) {
       address bcp = _method->bcp_from(bb->_end_bci);
-      int bc_len = Bytecodes::java_length_at(bcp);
+      int bc_len = Bytecodes::java_length_at(_method(), bcp);
       assert(bb->_end_bci + bc_len == bb[1]._bci, "unmatched bci info in basicblock");
     }
 #endif
@@ -985,7 +985,7 @@
 #ifdef ASSERT
   { BasicBlock *bb = &_basic_blocks[bbNo-1];
     address bcp = _method->bcp_from(bb->_end_bci);
-    int bc_len = Bytecodes::java_length_at(bcp);
+    int bc_len = Bytecodes::java_length_at(_method(), bcp);
     assert(bb->_end_bci + bc_len == _method->code_size(), "wrong end bci");
   }
 #endif
@@ -1837,14 +1837,14 @@
 
 
 void GenerateOopMap::do_ldc(int bci) {
-  Bytecode_loadconstant* ldc = Bytecode_loadconstant_at(method(), bci);
+  Bytecode_loadconstant ldc(method(), bci);
   constantPoolOop cp  = method()->constants();
-  BasicType       bt  = ldc->result_type();
+  BasicType       bt  = ldc.result_type();
   CellTypeState   cts = (bt == T_OBJECT) ? CellTypeState::make_line_ref(bci) : valCTS;
   // Make sure bt==T_OBJECT is the same as old code (is_pointer_entry).
   // Note that CONSTANT_MethodHandle entries are u2 index pairs, not pointer-entries,
   // and they are processed by _fast_aldc and the CP cache.
-  assert((ldc->has_cache_index() || cp->is_pointer_entry(ldc->pool_index()))
+  assert((ldc.has_cache_index() || cp->is_pointer_entry(ldc.pool_index()))
          ? (bt == T_OBJECT) : true, "expected object type");
   ppush1(cts);
 }
@@ -2343,7 +2343,7 @@
 bool GenerateOopMap::rewrite_load_or_store(BytecodeStream *bcs, Bytecodes::Code bcN, Bytecodes::Code bc0, unsigned int varNo) {
   assert(bcN == Bytecodes::_astore   || bcN == Bytecodes::_aload,   "wrong argument (bcN)");
   assert(bc0 == Bytecodes::_astore_0 || bc0 == Bytecodes::_aload_0, "wrong argument (bc0)");
-  int ilen = Bytecodes::length_at(bcs->bcp());
+  int ilen = Bytecodes::length_at(_method(), bcs->bcp());
   int newIlen;
 
   if (ilen == 4) {
--- a/src/share/vm/oops/methodDataOop.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/oops/methodDataOop.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -417,11 +417,11 @@
 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
   int cell_count = 0;
   if (stream->code() == Bytecodes::_tableswitch) {
-    Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
-    cell_count = 1 + per_case_cell_count * (1 + sw->length()); // 1 for default
+    Bytecode_tableswitch sw(stream->method()(), stream->bcp());
+    cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
   } else {
-    Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
-    cell_count = 1 + per_case_cell_count * (sw->number_of_pairs() + 1); // 1 for default
+    Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
+    cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default
   }
   return cell_count;
 }
@@ -434,35 +434,35 @@
   int target_di;
   int offset;
   if (stream->code() == Bytecodes::_tableswitch) {
-    Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
-    int len = sw->length();
+    Bytecode_tableswitch sw(stream->method()(), stream->bcp());
+    int len = sw.length();
     assert(array_len() == per_case_cell_count * (len + 1), "wrong len");
     for (int count = 0; count < len; count++) {
-      target = sw->dest_offset_at(count) + bci();
+      target = sw.dest_offset_at(count) + bci();
       my_di = mdo->dp_to_di(dp());
       target_di = mdo->bci_to_di(target);
       offset = target_di - my_di;
       set_displacement_at(count, offset);
     }
-    target = sw->default_offset() + bci();
+    target = sw.default_offset() + bci();
     my_di = mdo->dp_to_di(dp());
     target_di = mdo->bci_to_di(target);
     offset = target_di - my_di;
     set_default_displacement(offset);
 
   } else {
-    Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
-    int npairs = sw->number_of_pairs();
+    Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
+    int npairs = sw.number_of_pairs();
     assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
     for (int count = 0; count < npairs; count++) {
-      LookupswitchPair *pair = sw->pair_at(count);
-      target = pair->offset() + bci();
+      LookupswitchPair pair = sw.pair_at(count);
+      target = pair.offset() + bci();
       my_di = mdo->dp_to_di(dp());
       target_di = mdo->bci_to_di(target);
       offset = target_di - my_di;
       set_displacement_at(count, offset);
     }
-    target = sw->default_offset() + bci();
+    target = sw.default_offset() + bci();
     my_di = mdo->dp_to_di(dp());
     target_di = mdo->bci_to_di(target);
     offset = target_di - my_di;
--- a/src/share/vm/oops/methodOop.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/oops/methodOop.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -150,17 +150,6 @@
   return -1;
 }
 
-methodOop methodOopDesc::method_from_bcp(address bcp) {
-  debug_only(static int count = 0; count++);
-  assert(Universe::heap()->is_in_permanent(bcp), "bcp not in perm_gen");
-  // TO DO: this may be unsafe in some configurations
-  HeapWord* p = Universe::heap()->block_start(bcp);
-  assert(Universe::heap()->block_is_obj(p), "must be obj");
-  assert(oop(p)->is_constMethod(), "not a method");
-  return constMethodOop(p)->method();
-}
-
-
 void methodOopDesc::mask_for(int bci, InterpreterOopMap* mask) {
 
   Thread* myThread    = Thread::current();
@@ -469,11 +458,10 @@
 bool methodOopDesc::is_accessor() const {
   if (code_size() != 5) return false;
   if (size_of_parameters() != 1) return false;
-  methodOop m = (methodOop)this;  // pass to code_at() to avoid method_from_bcp
-  if (Bytecodes::java_code_at(code_base()+0, m) != Bytecodes::_aload_0 ) return false;
-  if (Bytecodes::java_code_at(code_base()+1, m) != Bytecodes::_getfield) return false;
-  if (Bytecodes::java_code_at(code_base()+4, m) != Bytecodes::_areturn &&
-      Bytecodes::java_code_at(code_base()+4, m) != Bytecodes::_ireturn ) return false;
+  if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
+  if (java_code_at(1) != Bytecodes::_getfield) return false;
+  if (java_code_at(4) != Bytecodes::_areturn &&
+      java_code_at(4) != Bytecodes::_ireturn ) return false;
   return true;
 }
 
@@ -1414,7 +1402,7 @@
 }
 
 
-Bytecodes::Code methodOopDesc::orig_bytecode_at(int bci) {
+Bytecodes::Code methodOopDesc::orig_bytecode_at(int bci) const {
   BreakpointInfo* bp = instanceKlass::cast(method_holder())->breakpoints();
   for (; bp != NULL; bp = bp->next()) {
     if (bp->match(this, bci)) {
--- a/src/share/vm/oops/methodOop.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/oops/methodOop.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -196,8 +196,15 @@
   static char* name_and_sig_as_C_string(Klass* klass, symbolOop method_name, symbolOop signature);
   static char* name_and_sig_as_C_string(Klass* klass, symbolOop method_name, symbolOop signature, char* buf, int size);
 
+  Bytecodes::Code java_code_at(int bci) const {
+    return Bytecodes::java_code_at(this, bcp_from(bci));
+  }
+  Bytecodes::Code code_at(int bci) const {
+    return Bytecodes::code_at(this, bcp_from(bci));
+  }
+
   // JVMTI breakpoints
-  Bytecodes::Code orig_bytecode_at(int bci);
+  Bytecodes::Code orig_bytecode_at(int bci) const;
   void        set_orig_bytecode_at(int bci, Bytecodes::Code code);
   void set_breakpoint(int bci);
   void clear_breakpoint(int bci);
@@ -655,8 +662,6 @@
   void set_queued_for_compilation()    { _access_flags.set_queued_for_compilation();     }
   void clear_queued_for_compilation()  { _access_flags.clear_queued_for_compilation();   }
 
-  static methodOop method_from_bcp(address bcp);
-
   // Resolve all classes in signature, return 'true' if successful
   static bool load_signature_classes(methodHandle m, TRAPS);
 
@@ -787,11 +792,11 @@
   void                 set_next(BreakpointInfo* n)    { _next = n; }
 
   // helps for searchers
-  bool match(methodOop m, int bci) {
+  bool match(const methodOopDesc* m, int bci) {
     return bci == _bci && match(m);
   }
 
-  bool match(methodOop m) {
+  bool match(const methodOopDesc* m) {
     return _name_index == m->name_index() &&
       _signature_index == m->signature_index();
   }
--- a/src/share/vm/prims/jvmtiRedefineClasses.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1458,7 +1458,7 @@
     if (bc_length == 0) {
       // More complicated bytecodes report a length of zero so
       // we have to try again a slightly different way.
-      bc_length = Bytecodes::length_at(bcp);
+      bc_length = Bytecodes::length_at(method(), bcp);
     }
 
     assert(bc_length != 0, "impossible bytecode length");
--- a/src/share/vm/prims/methodComparator.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/prims/methodComparator.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -194,10 +194,10 @@
 
   case Bytecodes::_ldc   : // fall through
   case Bytecodes::_ldc_w : {
-    Bytecode_loadconstant* ldc_old = Bytecode_loadconstant_at(_s_old->method(), _s_old->bci());
-    Bytecode_loadconstant* ldc_new = Bytecode_loadconstant_at(_s_new->method(), _s_new->bci());
-    int cpi_old = ldc_old->pool_index();
-    int cpi_new = ldc_new->pool_index();
+    Bytecode_loadconstant ldc_old(_s_old->method(), _s_old->bci());
+    Bytecode_loadconstant ldc_new(_s_new->method(), _s_new->bci());
+    int cpi_old = ldc_old.pool_index();
+    int cpi_new = ldc_new.pool_index();
     if (!pool_constants_same(cpi_old, cpi_new))
       return false;
     break;
@@ -267,8 +267,8 @@
   case Bytecodes::_ifnonnull : // fall through
   case Bytecodes::_ifnull    : // fall through
   case Bytecodes::_jsr       : {
-    int old_ofs = _s_old->bytecode()->get_offset_s2(c_old);
-    int new_ofs = _s_new->bytecode()->get_offset_s2(c_new);
+    int old_ofs = _s_old->bytecode().get_offset_s2(c_old);
+    int new_ofs = _s_new->bytecode().get_offset_s2(c_new);
     if (_switchable_test) {
       int old_dest = _s_old->bci() + old_ofs;
       int new_dest = _s_new->bci() + new_ofs;
@@ -304,8 +304,8 @@
 
   case Bytecodes::_goto_w : // fall through
   case Bytecodes::_jsr_w  : {
-    int old_ofs = _s_old->bytecode()->get_offset_s4(c_old);
-    int new_ofs = _s_new->bytecode()->get_offset_s4(c_new);
+    int old_ofs = _s_old->bytecode().get_offset_s4(c_old);
+    int new_ofs = _s_new->bytecode().get_offset_s4(c_new);
     if (_switchable_test) {
       int old_dest = _s_old->bci() + old_ofs;
       int new_dest = _s_new->bci() + new_ofs;
--- a/src/share/vm/runtime/deoptimization.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/runtime/deoptimization.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -395,8 +395,8 @@
   {
     HandleMark hm;
     methodHandle method(thread, array->element(0)->method());
-    Bytecode_invoke* invoke = Bytecode_invoke_at_check(method, array->element(0)->bci());
-    return_type = (invoke != NULL) ? invoke->result_type(thread) : T_ILLEGAL;
+    Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci());
+    return_type = invoke.is_valid() ? invoke.result_type(thread) : T_ILLEGAL;
   }
 
   // Compute information for handling adapters and adjusting the frame size of the caller.
@@ -600,8 +600,8 @@
           cur_code == Bytecodes::_invokespecial ||
           cur_code == Bytecodes::_invokestatic  ||
           cur_code == Bytecodes::_invokeinterface) {
-        Bytecode_invoke* invoke = Bytecode_invoke_at(mh, iframe->interpreter_frame_bci());
-        symbolHandle signature(thread, invoke->signature());
+        Bytecode_invoke invoke(mh, iframe->interpreter_frame_bci());
+        symbolHandle signature(thread, invoke.signature());
         ArgumentSizeComputer asc(signature);
         cur_invoke_parameter_size = asc.size();
         if (cur_code != Bytecodes::_invokestatic) {
@@ -963,7 +963,7 @@
       if (bci == SynchronizationEntryBCI) {
         code_name = "sync entry";
       } else {
-        Bytecodes::Code code = Bytecodes::code_at(vf->method(), bci);
+        Bytecodes::Code code = vf->method()->code_at(bci);
         code_name = Bytecodes::name(code);
       }
       tty->print(" - %s", code_name);
@@ -1224,7 +1224,7 @@
     ScopeDesc*      trap_scope  = cvf->scope();
     methodHandle    trap_method = trap_scope->method();
     int             trap_bci    = trap_scope->bci();
-    Bytecodes::Code trap_bc     = Bytecode_at(trap_method->bcp_from(trap_bci))->java_code();
+    Bytecodes::Code trap_bc     = trap_method->java_code_at(trap_bci);
 
     // Record this event in the histogram.
     gather_statistics(reason, action, trap_bc);
--- a/src/share/vm/runtime/frame.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/runtime/frame.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -930,10 +930,10 @@
   // This is used sometimes for calling into the VM, not for another
   // interpreted or compiled frame.
   if (!m->is_native()) {
-    Bytecode_invoke *call = Bytecode_invoke_at_check(m, bci);
-    if (call != NULL) {
-      signature = symbolHandle(thread, call->signature());
-      has_receiver = call->has_receiver();
+    Bytecode_invoke call = Bytecode_invoke_check(m, bci);
+    if (call.is_valid()) {
+      signature = symbolHandle(thread, call.signature());
+      has_receiver = call.has_receiver();
       if (map->include_argument_oops() &&
           interpreter_frame_expression_stack_size() > 0) {
         ResourceMark rm(thread);  // is this right ???
--- a/src/share/vm/runtime/relocator.hpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/runtime/relocator.hpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -106,7 +106,7 @@
   // get the address of in the code_array
   inline char* addr_at(int bci) const             { return (char*) &code_array()[bci]; }
 
-  int  instruction_length_at(int bci)             { return Bytecodes::length_at(code_array() + bci); }
+  int  instruction_length_at(int bci)             { return Bytecodes::length_at(_method(), code_array() + bci); }
 
   // Helper methods
   int  align(int n) const                          { return (n+3) & ~3; }
--- a/src/share/vm/runtime/sharedRuntime.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/runtime/sharedRuntime.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -944,9 +944,9 @@
   int          bci    = vfst.bci();
 
   // Find bytecode
-  Bytecode_invoke* bytecode = Bytecode_invoke_at(caller, bci);
-  bc = bytecode->java_code();
-  int bytecode_index = bytecode->index();
+  Bytecode_invoke bytecode(caller, bci);
+  bc = bytecode.java_code();
+  int bytecode_index = bytecode.index();
 
   // Find receiver for non-static call
   if (bc != Bytecodes::_invokestatic) {
@@ -957,7 +957,7 @@
     // Caller-frame is a compiled frame
     frame callerFrame = stubFrame.sender(&reg_map2);
 
-    methodHandle callee = bytecode->static_target(CHECK_(nullHandle));
+    methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
     if (callee.is_null()) {
       THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
     }
@@ -1674,10 +1674,9 @@
   // Get target class name from the checkcast instruction
   vframeStream vfst(thread, true);
   assert(!vfst.at_end(), "Java frame must exist");
-  Bytecode_checkcast* cc = Bytecode_checkcast_at(
-    vfst.method()->bcp_from(vfst.bci()));
+  Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
   Klass* targetKlass = Klass::cast(vfst.method()->constants()->klass_at(
-    cc->index(), thread));
+    cc.index(), thread));
   return generate_class_cast_message(objName, targetKlass->external_name());
 }
 
@@ -1711,11 +1710,11 @@
     const char* targetType = "the required signature";
     vframeStream vfst(thread, true);
     if (!vfst.at_end()) {
-      Bytecode_invoke* call = Bytecode_invoke_at(vfst.method(), vfst.bci());
+      Bytecode_invoke call(vfst.method(), vfst.bci());
       methodHandle target;
       {
         EXCEPTION_MARK;
-        target = call->static_target(THREAD);
+        target = call.static_target(THREAD);
         if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; }
       }
       if (target.not_null()
--- a/src/share/vm/runtime/vframeArray.cpp	Wed Jan 12 13:59:18 2011 -0800
+++ b/src/share/vm/runtime/vframeArray.cpp	Thu Jan 13 22:15:41 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -399,7 +399,7 @@
   } else if (TraceDeoptimization) {
     tty->print("     ");
     method()->print_value();
-    Bytecodes::Code code = Bytecodes::java_code_at(bcp);
+    Bytecodes::Code code = Bytecodes::java_code_at(method(), bcp);
     int bci = method()->bci_from(bcp);
     tty->print(" - %s", Bytecodes::name(code));
     tty->print(" @ bci %d ", bci);