src/share/vm/classfile/stackMapTableFormat.hpp

Thu, 26 Sep 2013 12:18:21 +0200

author
tschatzl
date
Thu, 26 Sep 2013 12:18:21 +0200
changeset 5775
461159cd7a91
parent 3992
4ee06e614636
child 6876
710a3c8b516e
child 8570
e4525db27263
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP
    26 #define SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP
    28 #include "classfile/verificationType.hpp"
    30 // These classes represent the stack-map substructures described in the JVMS
    31 // (hence the non-conforming naming scheme).
    33 // These classes work with the types in their compressed form in-place (as they
    34 // would appear in the classfile).  No virtual methods or fields allowed.
    36 class verification_type_info {
    37  private:
    38   // u1 tag
    39   // u2 cpool_index || u2 bci (for ITEM_Object & ITEM_Uninitailized only)
    41   address tag_addr() const { return (address)this; }
    42   address cpool_index_addr() const { return tag_addr() + sizeof(u1); }
    43   address bci_addr() const { return cpool_index_addr(); }
    45  protected:
    46   // No constructors  - should be 'private', but GCC issues a warning if it is
    47   verification_type_info() {}
    48   verification_type_info(const verification_type_info&) {}
    50  public:
    52   static verification_type_info* at(address addr) {
    53     return (verification_type_info*)addr;
    54   }
    56   static verification_type_info* create_at(address addr, u1 tag) {
    57     verification_type_info* vti = (verification_type_info*)addr;
    58     vti->set_tag(tag);
    59     return vti;
    60   }
    62   static verification_type_info* create_object_at(address addr, u2 cp_idx) {
    63     verification_type_info* vti = (verification_type_info*)addr;
    64     vti->set_tag(ITEM_Object);
    65     vti->set_cpool_index(cp_idx);
    66     return vti;
    67   }
    69   static verification_type_info* create_uninit_at(address addr, u2 bci) {
    70     verification_type_info* vti = (verification_type_info*)addr;
    71     vti->set_tag(ITEM_Uninitialized);
    72     vti->set_bci(bci);
    73     return vti;
    74   }
    76   static size_t calculate_size(u1 tag) {
    77     if (tag == ITEM_Object || tag == ITEM_Uninitialized) {
    78       return sizeof(u1) + sizeof(u2);
    79     } else {
    80       return sizeof(u1);
    81     }
    82   }
    84   static size_t max_size() { return sizeof(u1) + sizeof(u2); }
    86   u1 tag() const { return *(u1*)tag_addr(); }
    87   void set_tag(u1 tag) { *((u1*)tag_addr()) = tag; }
    89   bool is_object() const { return tag() == ITEM_Object; }
    90   bool is_uninitialized() const { return tag() == ITEM_Uninitialized; }
    92   u2 cpool_index() const {
    93     assert(is_object(), "This type has no cp_index");
    94     return Bytes::get_Java_u2(cpool_index_addr());
    95   }
    96   void set_cpool_index(u2 idx) {
    97     assert(is_object(), "This type has no cp_index");
    98     Bytes::put_Java_u2(cpool_index_addr(), idx);
    99   }
   101   u2 bci() const {
   102     assert(is_uninitialized(), "This type has no bci");
   103     return Bytes::get_Java_u2(bci_addr());
   104   }
   106   void set_bci(u2 bci) {
   107     assert(is_uninitialized(), "This type has no bci");
   108     Bytes::put_Java_u2(bci_addr(), bci);
   109   }
   111   void copy_from(verification_type_info* from) {
   112     set_tag(from->tag());
   113     if (from->is_object()) {
   114       set_cpool_index(from->cpool_index());
   115     } else if (from->is_uninitialized()) {
   116       set_bci(from->bci());
   117     }
   118   }
   120   size_t size() const {
   121     return calculate_size(tag());
   122   }
   124   verification_type_info* next() {
   125     return (verification_type_info*)((address)this + size());
   126   }
   128   // This method is used when reading unverified data in order to ensure
   129   // that we don't read past a particular memory limit.  It returns false
   130   // if any part of the data structure is outside the specified memory bounds.
   131   bool verify(address start, address end) {
   132     return ((address)this >= start &&
   133             (address)this < end &&
   134             (bci_addr() + sizeof(u2) <= end ||
   135                 !is_object() && !is_uninitialized()));
   136   }
   138   void print_on(outputStream* st) {
   139     switch (tag()) {
   140       case ITEM_Top: st->print("Top"); break;
   141       case ITEM_Integer: st->print("Integer"); break;
   142       case ITEM_Float: st->print("Float"); break;
   143       case ITEM_Double: st->print("Double"); break;
   144       case ITEM_Long: st->print("Long"); break;
   145       case ITEM_Null: st->print("Null"); break;
   146       case ITEM_UninitializedThis:
   147         st->print("UninitializedThis"); break;
   148       case ITEM_Uninitialized:
   149         st->print("Uninitialized[#%d]", bci()); break;
   150       case ITEM_Object:
   151         st->print("Object[#%d]", cpool_index()); break;
   152       default:
   153         assert(false, "Bad verification_type_info");
   154     }
   155   }
   156 };
   158 #define FOR_EACH_STACKMAP_FRAME_TYPE(macro, arg1, arg2) \
   159   macro(same_frame, arg1, arg2) \
   160   macro(same_frame_extended, arg1, arg2) \
   161   macro(same_locals_1_stack_item_frame, arg1, arg2) \
   162   macro(same_locals_1_stack_item_extended, arg1, arg2) \
   163   macro(chop_frame, arg1, arg2) \
   164   macro(append_frame, arg1, arg2) \
   165   macro(full_frame, arg1, arg2)
   167 #define SM_FORWARD_DECL(type, arg1, arg2) class type;
   168 FOR_EACH_STACKMAP_FRAME_TYPE(SM_FORWARD_DECL, x, x)
   169 #undef SM_FORWARD_DECL
   171 class stack_map_frame {
   172  protected:
   173   address frame_type_addr() const { return (address)this; }
   175   // No constructors  - should be 'private', but GCC issues a warning if it is
   176   stack_map_frame() {}
   177   stack_map_frame(const stack_map_frame&) {}
   179  public:
   181   static stack_map_frame* at(address addr) {
   182     return (stack_map_frame*)addr;
   183   }
   185   stack_map_frame* next() const {
   186     return at((address)this + size());
   187   }
   189   u1 frame_type() const { return *(u1*)frame_type_addr(); }
   190   void set_frame_type(u1 type) { *((u1*)frame_type_addr()) = type; }
   192   // pseudo-virtual methods
   193   inline size_t size() const;
   194   inline int offset_delta() const;
   195   inline void set_offset_delta(int offset_delta);
   196   inline int number_of_types() const; // number of types contained in the frame
   197   inline verification_type_info* types() const; // pointer to first type
   198   inline bool is_valid_offset(int offset_delta) const;
   200   // This method must be used when reading unverified data in order to ensure
   201   // that we don't read past a particular memory limit.  It returns false
   202   // if any part of the data structure is outside the specified memory bounds.
   203   inline bool verify(address start, address end) const;
   205   inline void print_on(outputStream* st, int current_offset) const;
   207   // Create as_xxx and is_xxx methods for the subtypes
   208 #define FRAME_TYPE_DECL(stackmap_frame_type, arg1, arg2) \
   209   inline stackmap_frame_type* as_##stackmap_frame_type() const; \
   210   bool is_##stackmap_frame_type() { \
   211     return as_##stackmap_frame_type() != NULL; \
   212   }
   214   FOR_EACH_STACKMAP_FRAME_TYPE(FRAME_TYPE_DECL, x, x)
   215 #undef FRAME_TYPE_DECL
   216 };
   218 class same_frame : public stack_map_frame {
   219  private:
   220   static int frame_type_to_offset_delta(u1 frame_type) {
   221       return frame_type + 1; }
   222   static u1 offset_delta_to_frame_type(int offset_delta) {
   223       return (u1)(offset_delta - 1); }
   225  public:
   227   static bool is_frame_type(u1 tag) {
   228     return tag < 64;
   229   }
   231   static same_frame* at(address addr) {
   232     assert(is_frame_type(*addr), "Wrong frame id");
   233     return (same_frame*)addr;
   234   }
   236   static same_frame* create_at(address addr, int offset_delta) {
   237     same_frame* sm = (same_frame*)addr;
   238     sm->set_offset_delta(offset_delta);
   239     return sm;
   240   }
   242   static size_t calculate_size() { return sizeof(u1); }
   244   size_t size() const { return calculate_size(); }
   245   int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
   247   void set_offset_delta(int offset_delta) {
   248     assert(offset_delta <= 64, "Offset too large for same_frame");
   249     set_frame_type(offset_delta_to_frame_type(offset_delta));
   250   }
   252   int number_of_types() const { return 0; }
   253   verification_type_info* types() const { return NULL; }
   255   bool is_valid_offset(int offset_delta) const {
   256     return is_frame_type(offset_delta_to_frame_type(offset_delta));
   257   }
   259   bool verify_subtype(address start, address end) const {
   260     return true;
   261   }
   263   void print_on(outputStream* st, int current_offset = -1) const {
   264     st->print("same_frame(@%d)", offset_delta() + current_offset);
   265   }
   266 };
   268 class same_frame_extended : public stack_map_frame {
   269  private:
   270   enum { _frame_id = 251 };
   271   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   273  public:
   274   static bool is_frame_type(u1 tag) {
   275     return tag == _frame_id;
   276   }
   278   static same_frame_extended* at(address addr) {
   279     assert(is_frame_type(*addr), "Wrong frame type");
   280     return (same_frame_extended*)addr;
   281   }
   283   static same_frame_extended* create_at(address addr, u2 offset_delta) {
   284     same_frame_extended* sm = (same_frame_extended*)addr;
   285     sm->set_frame_type(_frame_id);
   286     sm->set_offset_delta(offset_delta);
   287     return sm;
   288   }
   290   static size_t calculate_size() { return sizeof(u1) + sizeof(u2); }
   292   size_t size() const { return calculate_size(); }
   293   int offset_delta() const {
   294     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   295   }
   297   void set_offset_delta(int offset_delta) {
   298     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   299   }
   301   int number_of_types() const { return 0; }
   302   verification_type_info* types() const { return NULL; }
   303   bool is_valid_offset(int offset) const { return true; }
   305   bool verify_subtype(address start, address end) const {
   306     return frame_type_addr() + size() <= end;
   307   }
   309   void print_on(outputStream* st, int current_offset = -1) const {
   310     st->print("same_frame_extended(@%d)", offset_delta() + current_offset);
   311   }
   312 };
   314 class same_locals_1_stack_item_frame : public stack_map_frame {
   315  private:
   316   address type_addr() const { return frame_type_addr() + sizeof(u1); }
   318   static int frame_type_to_offset_delta(u1 frame_type) {
   319       return frame_type - 63; }
   320   static u1 offset_delta_to_frame_type(int offset_delta) {
   321       return (u1)(offset_delta + 63); }
   323  public:
   324   static bool is_frame_type(u1 tag) {
   325     return tag >= 64 && tag < 128;
   326   }
   328   static same_locals_1_stack_item_frame* at(address addr) {
   329     assert(is_frame_type(*addr), "Wrong frame id");
   330     return (same_locals_1_stack_item_frame*)addr;
   331   }
   333   static same_locals_1_stack_item_frame* create_at(
   334       address addr, int offset_delta, verification_type_info* vti) {
   335     same_locals_1_stack_item_frame* sm = (same_locals_1_stack_item_frame*)addr;
   336     sm->set_offset_delta(offset_delta);
   337     if (vti != NULL) {
   338       sm->set_type(vti);
   339     }
   340     return sm;
   341   }
   343   static size_t calculate_size(verification_type_info* vti) {
   344     return sizeof(u1) + vti->size();
   345   }
   347   static size_t max_size() {
   348     return sizeof(u1) + verification_type_info::max_size();
   349   }
   351   size_t size() const { return calculate_size(types()); }
   352   int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
   354   void set_offset_delta(int offset_delta) {
   355     assert(offset_delta > 0 && offset_delta <= 64,
   356            "Offset too large for this frame type");
   357     set_frame_type(offset_delta_to_frame_type(offset_delta));
   358   }
   360   void set_type(verification_type_info* vti) {
   361     verification_type_info* cur = types();
   362     cur->copy_from(vti);
   363   }
   365   int number_of_types() const { return 1; }
   366   verification_type_info* types() const {
   367     return verification_type_info::at(type_addr());
   368   }
   370   bool is_valid_offset(int offset_delta) const {
   371     return is_frame_type(offset_delta_to_frame_type(offset_delta));
   372   }
   374   bool verify_subtype(address start, address end) const {
   375     return types()->verify(start, end);
   376   }
   378   void print_on(outputStream* st, int current_offset = -1) const {
   379     st->print("same_locals_1_stack_item_frame(@%d,",
   380         offset_delta() + current_offset);
   381     types()->print_on(st);
   382     st->print(")");
   383   }
   384 };
   386 class same_locals_1_stack_item_extended : public stack_map_frame {
   387  private:
   388   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   389   address type_addr() const { return offset_delta_addr() + sizeof(u2); }
   391   enum { _frame_id = 247 };
   393  public:
   394   static bool is_frame_type(u1 tag) {
   395     return tag == _frame_id;
   396   }
   398   static same_locals_1_stack_item_extended* at(address addr) {
   399     assert(is_frame_type(*addr), "Wrong frame id");
   400     return (same_locals_1_stack_item_extended*)addr;
   401   }
   403   static same_locals_1_stack_item_extended* create_at(
   404       address addr, int offset_delta, verification_type_info* vti) {
   405     same_locals_1_stack_item_extended* sm =
   406        (same_locals_1_stack_item_extended*)addr;
   407     sm->set_frame_type(_frame_id);
   408     sm->set_offset_delta(offset_delta);
   409     if (vti != NULL) {
   410       sm->set_type(vti);
   411     }
   412     return sm;
   413   }
   415   static size_t calculate_size(verification_type_info* vti) {
   416     return sizeof(u1) + sizeof(u2) + vti->size();
   417   }
   419   size_t size() const { return calculate_size(types()); }
   420   int offset_delta() const {
   421     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   422   }
   424   void set_offset_delta(int offset_delta) {
   425     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   426   }
   428   void set_type(verification_type_info* vti) {
   429     verification_type_info* cur = types();
   430     cur->copy_from(vti);
   431   }
   433   int number_of_types() const { return 1; }
   434   verification_type_info* types() const {
   435     return verification_type_info::at(type_addr());
   436   }
   437   bool is_valid_offset(int offset) { return true; }
   439   bool verify_subtype(address start, address end) const {
   440     return type_addr() < end && types()->verify(start, end);
   441   }
   443   void print_on(outputStream* st, int current_offset = -1) const {
   444     st->print("same_locals_1_stack_item_extended(@%d,",
   445         offset_delta() + current_offset);
   446     types()->print_on(st);
   447     st->print(")");
   448   }
   449 };
   451 class chop_frame : public stack_map_frame {
   452  private:
   453   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   455   static int frame_type_to_chops(u1 frame_type) {
   456     int chop = 251 - frame_type;
   457     return chop;
   458   }
   460   static u1 chops_to_frame_type(int chop) {
   461     return 251 - chop;
   462   }
   464  public:
   465   static bool is_frame_type(u1 tag) {
   466     return frame_type_to_chops(tag) > 0 && frame_type_to_chops(tag) < 4;
   467   }
   469   static chop_frame* at(address addr) {
   470     assert(is_frame_type(*addr), "Wrong frame id");
   471     return (chop_frame*)addr;
   472   }
   474   static chop_frame* create_at(address addr, int offset_delta, int chops) {
   475     chop_frame* sm = (chop_frame*)addr;
   476     sm->set_chops(chops);
   477     sm->set_offset_delta(offset_delta);
   478     return sm;
   479   }
   481   static size_t calculate_size() {
   482     return sizeof(u1) + sizeof(u2);
   483   }
   485   size_t size() const { return calculate_size(); }
   486   int offset_delta() const {
   487     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   488   }
   489   void set_offset_delta(int offset_delta) {
   490     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   491   }
   493   int chops() const {
   494     int chops = frame_type_to_chops(frame_type());
   495     assert(chops > 0 && chops < 4, "Invalid number of chops in frame");
   496     return chops;
   497   }
   498   void set_chops(int chops) {
   499     assert(chops > 0 && chops <= 3, "Bad number of chops");
   500     set_frame_type(chops_to_frame_type(chops));
   501   }
   503   int number_of_types() const { return 0; }
   504   verification_type_info* types() const { return NULL; }
   505   bool is_valid_offset(int offset) { return true; }
   507   bool verify_subtype(address start, address end) const {
   508     return frame_type_addr() + size() <= end;
   509   }
   511   void print_on(outputStream* st, int current_offset = -1) const {
   512     st->print("chop_frame(@%d,%d)", offset_delta() + current_offset, chops());
   513   }
   514 };
   516 class append_frame : public stack_map_frame {
   517  private:
   518   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   519   address types_addr() const { return offset_delta_addr() + sizeof(u2); }
   521   static int frame_type_to_appends(u1 frame_type) {
   522     int append = frame_type - 251;
   523     return append;
   524   }
   526   static u1 appends_to_frame_type(int appends) {
   527     assert(appends > 0 && appends < 4, "Invalid append amount");
   528     return 251 + appends;
   529   }
   531  public:
   532   static bool is_frame_type(u1 tag) {
   533     return frame_type_to_appends(tag) > 0 && frame_type_to_appends(tag) < 4;
   534   }
   536   static append_frame* at(address addr) {
   537     assert(is_frame_type(*addr), "Wrong frame id");
   538     return (append_frame*)addr;
   539   }
   541   static append_frame* create_at(
   542       address addr, int offset_delta, int appends,
   543       verification_type_info* types) {
   544     append_frame* sm = (append_frame*)addr;
   545     sm->set_appends(appends);
   546     sm->set_offset_delta(offset_delta);
   547     if (types != NULL) {
   548       verification_type_info* cur = sm->types();
   549       for (int i = 0; i < appends; ++i) {
   550         cur->copy_from(types);
   551         cur = cur->next();
   552         types = types->next();
   553       }
   554     }
   555     return sm;
   556   }
   558   static size_t calculate_size(int appends, verification_type_info* types) {
   559     size_t sz = sizeof(u1) + sizeof(u2);
   560     for (int i = 0; i < appends; ++i) {
   561       sz += types->size();
   562       types = types->next();
   563     }
   564     return sz;
   565   }
   567   static size_t max_size() {
   568     return sizeof(u1) + sizeof(u2) + 3 * verification_type_info::max_size();
   569   }
   571   size_t size() const { return calculate_size(number_of_types(), types()); }
   572   int offset_delta() const {
   573     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   574   }
   576   void set_offset_delta(int offset_delta) {
   577     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   578   }
   580   void set_appends(int appends) {
   581     assert(appends > 0 && appends < 4, "Bad number of appends");
   582     set_frame_type(appends_to_frame_type(appends));
   583   }
   585   int number_of_types() const {
   586     int appends = frame_type_to_appends(frame_type());
   587     assert(appends > 0 && appends < 4, "Invalid number of appends in frame");
   588     return appends;
   589   }
   590   verification_type_info* types() const {
   591     return verification_type_info::at(types_addr());
   592   }
   593   bool is_valid_offset(int offset) const { return true; }
   595   bool verify_subtype(address start, address end) const {
   596     verification_type_info* vti = types();
   597     if ((address)vti < end && vti->verify(start, end)) {
   598       int nof = number_of_types();
   599       vti = vti->next();
   600       if (nof < 2 || vti->verify(start, end)) {
   601         vti = vti->next();
   602         if (nof < 3 || vti->verify(start, end)) {
   603           return true;
   604         }
   605       }
   606     }
   607     return false;
   608   }
   610   void print_on(outputStream* st, int current_offset = -1) const {
   611     st->print("append_frame(@%d,", offset_delta() + current_offset);
   612     verification_type_info* vti = types();
   613     for (int i = 0; i < number_of_types(); ++i) {
   614       vti->print_on(st);
   615       if (i != number_of_types() - 1) {
   616         st->print(",");
   617       }
   618       vti = vti->next();
   619     }
   620     st->print(")");
   621   }
   622 };
   624 class full_frame : public stack_map_frame {
   625  private:
   626   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   627   address num_locals_addr() const { return offset_delta_addr() + sizeof(u2); }
   628   address locals_addr() const { return num_locals_addr() + sizeof(u2); }
   629   address stack_slots_addr(address end_of_locals) const {
   630       return end_of_locals; }
   631   address stack_addr(address end_of_locals) const {
   632       return stack_slots_addr(end_of_locals) + sizeof(u2); }
   634   enum { _frame_id = 255 };
   636  public:
   637   static bool is_frame_type(u1 tag) {
   638     return tag == _frame_id;
   639   }
   641   static full_frame* at(address addr) {
   642     assert(is_frame_type(*addr), "Wrong frame id");
   643     return (full_frame*)addr;
   644   }
   646   static full_frame* create_at(
   647       address addr, int offset_delta, int num_locals,
   648       verification_type_info* locals,
   649       int stack_slots, verification_type_info* stack) {
   650     full_frame* sm = (full_frame*)addr;
   651     sm->set_frame_type(_frame_id);
   652     sm->set_offset_delta(offset_delta);
   653     sm->set_num_locals(num_locals);
   654     if (locals != NULL) {
   655       verification_type_info* cur = sm->locals();
   656       for (int i = 0; i < num_locals; ++i) {
   657         cur->copy_from(locals);
   658         cur = cur->next();
   659         locals = locals->next();
   660       }
   661       address end_of_locals = (address)cur;
   662       sm->set_stack_slots(end_of_locals, stack_slots);
   663       cur = sm->stack(end_of_locals);
   664       for (int i = 0; i < stack_slots; ++i) {
   665         cur->copy_from(stack);
   666         cur = cur->next();
   667         stack = stack->next();
   668       }
   669     }
   670     return sm;
   671   }
   673   static size_t calculate_size(
   674       int num_locals, verification_type_info* locals,
   675       int stack_slots, verification_type_info* stack) {
   676     size_t sz = sizeof(u1) + sizeof(u2) + sizeof(u2) + sizeof(u2);
   677     verification_type_info* vti = locals;
   678     for (int i = 0; i < num_locals; ++i) {
   679       sz += vti->size();
   680       vti = vti->next();
   681     }
   682     vti = stack;
   683     for (int i = 0; i < stack_slots; ++i) {
   684       sz += vti->size();
   685       vti = vti->next();
   686     }
   687     return sz;
   688   }
   690   static size_t max_size(int locals, int stack) {
   691     return sizeof(u1) + 3 * sizeof(u2) +
   692         (locals + stack) * verification_type_info::max_size();
   693   }
   695   size_t size() const {
   696     address eol = end_of_locals();
   697     return calculate_size(num_locals(), locals(), stack_slots(eol), stack(eol));
   698   }
   700   int offset_delta() const {
   701     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   702   }
   703   int num_locals() const { return Bytes::get_Java_u2(num_locals_addr()); }
   704   verification_type_info* locals() const {
   705     return verification_type_info::at(locals_addr());
   706   }
   707   address end_of_locals() const {
   708     verification_type_info* vti = locals();
   709     for (int i = 0; i < num_locals(); ++i) {
   710       vti = vti->next();
   711     }
   712     return (address)vti;
   713   }
   714   int stack_slots(address end_of_locals) const {
   715     return Bytes::get_Java_u2(stack_slots_addr(end_of_locals));
   716   }
   717   verification_type_info* stack(address end_of_locals) const {
   718     return verification_type_info::at(stack_addr(end_of_locals));
   719   }
   721   void set_offset_delta(int offset_delta) {
   722     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   723   }
   724   void set_num_locals(int num_locals) {
   725     Bytes::put_Java_u2(num_locals_addr(), num_locals);
   726   }
   727   void set_stack_slots(address end_of_locals, int stack_slots) {
   728     Bytes::put_Java_u2(stack_slots_addr(end_of_locals), stack_slots);
   729   }
   731   // These return only the locals.  Extra processing is required for stack
   732   // types of full frames.
   733   int number_of_types() const { return num_locals(); }
   734   verification_type_info* types() const { return locals(); }
   735   bool is_valid_offset(int offset) { return true; }
   737   bool verify_subtype(address start, address end) const {
   738     verification_type_info* vti = types();
   739     if ((address)vti >= end) {
   740       return false;
   741     }
   742     int count = number_of_types();
   743     for (int i = 0; i < count; ++i) {
   744       if (!vti->verify(start, end)) {
   745         return false;
   746       }
   747       vti = vti->next();
   748     }
   749     address eol = (address)vti;
   750     if (eol + sizeof(u2) > end) {
   751       return false;
   752     }
   753     count = stack_slots(eol);
   754     vti = stack(eol);
   755     for (int i = 0; i < stack_slots(eol); ++i) {
   756       if (!vti->verify(start, end)) {
   757         return false;
   758       }
   759       vti = vti->next();
   760     }
   761     return true;
   762   }
   764   void print_on(outputStream* st, int current_offset = -1) const {
   765     st->print("full_frame(@%d,{", offset_delta() + current_offset);
   766     verification_type_info* vti = locals();
   767     for (int i = 0; i < num_locals(); ++i) {
   768       vti->print_on(st);
   769       if (i != num_locals() - 1) {
   770         st->print(",");
   771       }
   772       vti = vti->next();
   773     }
   774     st->print("},{");
   775     address end_of_locals = (address)vti;
   776     vti = stack(end_of_locals);
   777     int ss = stack_slots(end_of_locals);
   778     for (int i = 0; i < ss; ++i) {
   779       vti->print_on(st);
   780       if (i != ss - 1) {
   781         st->print(",");
   782       }
   783       vti = vti->next();
   784     }
   785     st->print("})");
   786   }
   787 };
   789 #define VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
   790   stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
   791   if (item_##stack_frame_type != NULL) { \
   792     return item_##stack_frame_type->func_name args;  \
   793   }
   795 #define VOID_VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
   796   stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
   797   if (item_##stack_frame_type != NULL) { \
   798     item_##stack_frame_type->func_name args;  \
   799     return; \
   800   }
   802 size_t stack_map_frame::size() const {
   803   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, size, ());
   804   return 0;
   805 }
   807 int stack_map_frame::offset_delta() const {
   808   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, offset_delta, ());
   809   return 0;
   810 }
   812 void stack_map_frame::set_offset_delta(int offset_delta) {
   813   FOR_EACH_STACKMAP_FRAME_TYPE(
   814       VOID_VIRTUAL_DISPATCH, set_offset_delta, (offset_delta));
   815 }
   817 int stack_map_frame::number_of_types() const {
   818   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, number_of_types, ());
   819   return 0;
   820 }
   822 verification_type_info* stack_map_frame::types() const {
   823   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, types, ());
   824   return NULL;
   825 }
   827 bool stack_map_frame::is_valid_offset(int offset) const {
   828   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, is_valid_offset, (offset));
   829   return true;
   830 }
   832 bool stack_map_frame::verify(address start, address end) const {
   833   if (frame_type_addr() >= start && frame_type_addr() < end) {
   834     FOR_EACH_STACKMAP_FRAME_TYPE(
   835        VIRTUAL_DISPATCH, verify_subtype, (start, end));
   836   }
   837   return false;
   838 }
   840 void stack_map_frame::print_on(outputStream* st, int offs = -1) const {
   841   FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_on, (st, offs));
   842 }
   844 #undef VIRTUAL_DISPATCH
   845 #undef VOID_VIRTUAL_DISPATCH
   847 #define AS_SUBTYPE_DEF(stack_frame_type, arg1, arg2) \
   848 stack_frame_type* stack_map_frame::as_##stack_frame_type() const { \
   849   if (stack_frame_type::is_frame_type(frame_type())) { \
   850     return (stack_frame_type*)this; \
   851   } else { \
   852     return NULL; \
   853   } \
   854 }
   856 FOR_EACH_STACKMAP_FRAME_TYPE(AS_SUBTYPE_DEF, x, x)
   857 #undef AS_SUBTYPE_DEF
   859 class stack_map_table {
   860  private:
   861   address number_of_entries_addr() const {
   862     return (address)this;
   863   }
   864   address entries_addr() const {
   865     return number_of_entries_addr() + sizeof(u2);
   866   }
   868  protected:
   869   // No constructors  - should be 'private', but GCC issues a warning if it is
   870   stack_map_table() {}
   871   stack_map_table(const stack_map_table&) {}
   873  public:
   875   static stack_map_table* at(address addr) {
   876     return (stack_map_table*)addr;
   877   }
   879   u2 number_of_entries() const {
   880     return Bytes::get_Java_u2(number_of_entries_addr());
   881   }
   882   stack_map_frame* entries() const {
   883     return stack_map_frame::at(entries_addr());
   884   }
   886   void set_number_of_entries(u2 num) {
   887     Bytes::put_Java_u2(number_of_entries_addr(), num);
   888   }
   889 };
   891 class stack_map_table_attribute {
   892  private:
   893   address name_index_addr() const {
   894       return (address)this; }
   895   address attribute_length_addr() const {
   896       return name_index_addr() + sizeof(u2); }
   897   address stack_map_table_addr() const {
   898       return attribute_length_addr() + sizeof(u4); }
   900  protected:
   901   // No constructors  - should be 'private', but GCC issues a warning if it is
   902   stack_map_table_attribute() {}
   903   stack_map_table_attribute(const stack_map_table_attribute&) {}
   905  public:
   907   static stack_map_table_attribute* at(address addr) {
   908     return (stack_map_table_attribute*)addr;
   909   }
   911   u2 name_index() const {
   912     return Bytes::get_Java_u2(name_index_addr()); }
   913   u4 attribute_length() const {
   914     return Bytes::get_Java_u4(attribute_length_addr()); }
   915   stack_map_table* table() const {
   916     return stack_map_table::at(stack_map_table_addr());
   917   }
   919   void set_name_index(u2 idx) {
   920     Bytes::put_Java_u2(name_index_addr(), idx);
   921   }
   922   void set_attribute_length(u4 len) {
   923     Bytes::put_Java_u4(attribute_length_addr(), len);
   924   }
   925 };
   927 #undef FOR_EACH_STACKMAP_FRAME_TYPE
   929 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP

mercurial