Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/vm/opto/library_call.cpp
          +++ new/src/share/vm/opto/library_call.cpp
   1    1  /*
   2      - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
   3    3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4    4   *
   5    5   * This code is free software; you can redistribute it and/or modify it
   6    6   * under the terms of the GNU General Public License version 2 only, as
   7    7   * published by the Free Software Foundation.
   8    8   *
   9    9   * This code is distributed in the hope that it will be useful, but WITHOUT
  10   10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11   11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12   12   * version 2 for more details (a copy is included in the LICENSE file that
↓ open down ↓ 77 lines elided ↑ open up ↑
  90   90                                  // resulting CastII of index:
  91   91                                  Node* *pos_index = NULL);
  92   92    Node* generate_nonpositive_guard(Node* index, bool never_negative,
  93   93                                     // resulting CastII of index:
  94   94                                     Node* *pos_index = NULL);
  95   95    Node* generate_limit_guard(Node* offset, Node* subseq_length,
  96   96                               Node* array_length,
  97   97                               RegionNode* region);
  98   98    Node* generate_current_thread(Node* &tls_output);
  99   99    address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset,
 100      -                              bool disjoint_bases, const char* &name);
      100 +                              bool disjoint_bases, const char* &name, bool need_pre_barrier = true);
 101  101    Node* load_mirror_from_klass(Node* klass);
 102  102    Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
 103  103                                        int nargs,
 104  104                                        RegionNode* region, int null_path,
 105  105                                        int offset);
 106  106    Node* load_klass_from_mirror(Node* mirror, bool never_see_null, int nargs,
 107  107                                 RegionNode* region, int null_path) {
 108  108      int offset = java_lang_Class::klass_offset_in_bytes();
 109  109      return load_klass_from_mirror_common(mirror, never_see_null, nargs,
 110  110                                           region, null_path,
↓ open down ↓ 103 lines elided ↑ open up ↑
 214  214                                  Node* dest, Node* dest_offset,
 215  215                                  Node* dest_size);
 216  216    void generate_slow_arraycopy(const TypePtr* adr_type,
 217  217                                 Node* src,  Node* src_offset,
 218  218                                 Node* dest, Node* dest_offset,
 219  219                                 Node* copy_length);
 220  220    Node* generate_checkcast_arraycopy(const TypePtr* adr_type,
 221  221                                       Node* dest_elem_klass,
 222  222                                       Node* src,  Node* src_offset,
 223  223                                       Node* dest, Node* dest_offset,
 224      -                                     Node* copy_length);
      224 +                                     Node* copy_length, bool need_pre_barrier = true);
 225  225    Node* generate_generic_arraycopy(const TypePtr* adr_type,
 226  226                                     Node* src,  Node* src_offset,
 227  227                                     Node* dest, Node* dest_offset,
 228  228                                     Node* copy_length);
 229  229    void generate_unchecked_arraycopy(const TypePtr* adr_type,
 230  230                                      BasicType basic_elem_type,
 231  231                                      bool disjoint_bases,
 232  232                                      Node* src,  Node* src_offset,
 233  233                                      Node* dest, Node* dest_offset,
 234      -                                    Node* copy_length);
      234 +                                    Node* copy_length, bool need_pre_barrier = true);
 235  235    bool inline_unsafe_CAS(BasicType type);
 236  236    bool inline_unsafe_ordered_store(BasicType type);
 237  237    bool inline_fp_conversions(vmIntrinsics::ID id);
 238  238    bool inline_numberOfLeadingZeros(vmIntrinsics::ID id);
 239  239    bool inline_numberOfTrailingZeros(vmIntrinsics::ID id);
 240  240    bool inline_bitCount(vmIntrinsics::ID id);
 241  241    bool inline_reverseBytes(vmIntrinsics::ID id);
 242  242  };
 243  243  
 244  244  
↓ open down ↓ 4043 lines elided ↑ open up ↑
4288 4288  enum {
4289 4289    COPYFUNC_UNALIGNED = 0,
4290 4290    COPYFUNC_ALIGNED = 1,                 // src, dest aligned to HeapWordSize
4291 4291    COPYFUNC_CONJOINT = 0,
4292 4292    COPYFUNC_DISJOINT = 2                 // src != dest, or transfer can descend
4293 4293  };
4294 4294  
4295 4295  // Note:  The condition "disjoint" applies also for overlapping copies
4296 4296  // where an descending copy is permitted (i.e., dest_offset <= src_offset).
4297 4297  static address
4298      -select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name) {
     4298 +select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name, bool need_pre_barrier) {
4299 4299    int selector =
4300 4300      (aligned  ? COPYFUNC_ALIGNED  : COPYFUNC_UNALIGNED) +
4301 4301      (disjoint ? COPYFUNC_DISJOINT : COPYFUNC_CONJOINT);
4302 4302  
4303 4303  #define RETURN_STUB(xxx_arraycopy) { \
4304 4304    name = #xxx_arraycopy; \
4305 4305    return StubRoutines::xxx_arraycopy(); }
4306 4306  
     4307 +#define RETURN_STUB_PARM(xxx_arraycopy, parm) {           \
     4308 +  name = #xxx_arraycopy; \
     4309 +  return StubRoutines::xxx_arraycopy(parm); }
     4310 +
4307 4311    switch (t) {
4308 4312    case T_BYTE:
4309 4313    case T_BOOLEAN:
4310 4314      switch (selector) {
4311 4315      case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB(jbyte_arraycopy);
4312 4316      case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED:    RETURN_STUB(arrayof_jbyte_arraycopy);
4313 4317      case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB(jbyte_disjoint_arraycopy);
4314 4318      case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED:    RETURN_STUB(arrayof_jbyte_disjoint_arraycopy);
4315 4319      }
4316 4320    case T_CHAR:
↓ open down ↓ 16 lines elided ↑ open up ↑
4333 4337    case T_LONG:
4334 4338      switch (selector) {
4335 4339      case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB(jlong_arraycopy);
4336 4340      case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED:    RETURN_STUB(arrayof_jlong_arraycopy);
4337 4341      case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB(jlong_disjoint_arraycopy);
4338 4342      case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED:    RETURN_STUB(arrayof_jlong_disjoint_arraycopy);
4339 4343      }
4340 4344    case T_ARRAY:
4341 4345    case T_OBJECT:
4342 4346      switch (selector) {
4343      -    case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB(oop_arraycopy);
4344      -    case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED:    RETURN_STUB(arrayof_oop_arraycopy);
4345      -    case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB(oop_disjoint_arraycopy);
4346      -    case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED:    RETURN_STUB(arrayof_oop_disjoint_arraycopy);
     4347 +    case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB_PARM(oop_arraycopy, need_pre_barrier);
     4348 +    case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED:    RETURN_STUB_PARM(arrayof_oop_arraycopy, need_pre_barrier);
     4349 +    case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED:  RETURN_STUB_PARM(oop_disjoint_arraycopy, need_pre_barrier);
     4350 +    case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED:    RETURN_STUB_PARM(arrayof_oop_disjoint_arraycopy, need_pre_barrier);
4347 4351      }
4348 4352    default:
4349 4353      ShouldNotReachHere();
4350 4354      return NULL;
4351 4355    }
4352 4356  
4353 4357  #undef RETURN_STUB
     4358 +#undef RETURN_STUB_PARM
4354 4359  }
4355 4360  
4356 4361  //------------------------------basictype2arraycopy----------------------------
4357 4362  address LibraryCallKit::basictype2arraycopy(BasicType t,
4358 4363                                              Node* src_offset,
4359 4364                                              Node* dest_offset,
4360 4365                                              bool disjoint_bases,
4361      -                                            const char* &name) {
     4366 +                                            const char* &name,
     4367 +                                            bool need_pre_barrier) {
4362 4368    const TypeInt* src_offset_inttype  = gvn().find_int_type(src_offset);;
4363 4369    const TypeInt* dest_offset_inttype = gvn().find_int_type(dest_offset);;
4364 4370  
4365 4371    bool aligned = false;
4366 4372    bool disjoint = disjoint_bases;
4367 4373  
4368 4374    // if the offsets are the same, we can treat the memory regions as
4369 4375    // disjoint, because either the memory regions are in different arrays,
4370 4376    // or they are identical (which we can treat as disjoint.)  We can also
4371 4377    // treat a copy with a destination index  less that the source index
↓ open down ↓ 5 lines elided ↑ open up ↑
4377 4383      int d_offs = dest_offset_inttype->get_con();
4378 4384      int element_size = type2aelembytes(t);
4379 4385      aligned = ((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&
4380 4386                ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0);
4381 4387      if (s_offs >= d_offs)  disjoint = true;
4382 4388    } else if (src_offset == dest_offset && src_offset != NULL) {
4383 4389      // This can occur if the offsets are identical non-constants.
4384 4390      disjoint = true;
4385 4391    }
4386 4392  
4387      -  return select_arraycopy_function(t, aligned, disjoint, name);
     4393 +  return select_arraycopy_function(t, aligned, disjoint, name, need_pre_barrier);
4388 4394  }
4389 4395  
4390 4396  
4391 4397  //------------------------------inline_arraycopy-----------------------
4392 4398  bool LibraryCallKit::inline_arraycopy() {
4393 4399    // Restore the stack and pop off the arguments.
4394 4400    int nargs = 5;  // 2 oops, 3 ints, no size_t or long
4395 4401    assert(callee()->signature()->size() == nargs, "copy has 5 arguments");
4396 4402  
4397 4403    Node *src         = argument(0);
↓ open down ↓ 369 lines elided ↑ open up ↑
4767 4773        PreserveJVMState pjvms(this);
4768 4774        set_control(not_subtype_ctrl);
4769 4775        // (At this point we can assume disjoint_bases, since types differ.)
4770 4776        int ek_offset = objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc);
4771 4777        Node* p1 = basic_plus_adr(dest_klass, ek_offset);
4772 4778        Node* n1 = LoadKlassNode::make(_gvn, immutable_memory(), p1, TypeRawPtr::BOTTOM);
4773 4779        Node* dest_elem_klass = _gvn.transform(n1);
4774 4780        Node* cv = generate_checkcast_arraycopy(adr_type,
4775 4781                                                dest_elem_klass,
4776 4782                                                src, src_offset, dest, dest_offset,
4777      -                                              ConvI2X(copy_length));
     4783 +                                              ConvI2X(copy_length), !must_clear_dest);
4778 4784        if (cv == NULL)  cv = intcon(-1);  // failure (no stub available)
4779 4785        checked_control = control();
4780 4786        checked_i_o     = i_o();
4781 4787        checked_mem     = memory(adr_type);
4782 4788        checked_value   = cv;
4783 4789      }
4784 4790      // At this point we know we do not need type checks on oop stores.
4785 4791  
4786 4792      // Let's see if we need card marks:
4787 4793      if (alloc != NULL && use_ReduceInitialCardMarks()) {
↓ open down ↓ 2 lines elided ↑ open up ↑
4790 4796        assert(type2aelembytes(basic_elem_type) == type2aelembytes(copy_type),
4791 4797               "sizes agree");
4792 4798      }
4793 4799    }
4794 4800  
4795 4801    if (!stopped()) {
4796 4802      // Generate the fast path, if possible.
4797 4803      PreserveJVMState pjvms(this);
4798 4804      generate_unchecked_arraycopy(adr_type, copy_type, disjoint_bases,
4799 4805                                   src, src_offset, dest, dest_offset,
4800      -                                 ConvI2X(copy_length));
     4806 +                                 ConvI2X(copy_length), !must_clear_dest);
4801 4807  
4802 4808      // Present the results of the fast call.
4803 4809      result_region->init_req(fast_path, control());
4804 4810      result_i_o   ->init_req(fast_path, i_o());
4805 4811      result_memory->init_req(fast_path, memory(adr_type));
4806 4812    }
4807 4813  
4808 4814    // Here are all the slow paths up to this point, in one bundle:
4809 4815    slow_control = top();
4810 4816    if (slow_region != NULL)
↓ open down ↓ 386 lines elided ↑ open up ↑
5197 5203    // Handle exceptions thrown by this fellow:
5198 5204    make_slow_call_ex(call, env()->Throwable_klass(), false);
5199 5205  }
5200 5206  
5201 5207  // Helper function; generates code for cases requiring runtime checks.
5202 5208  Node*
5203 5209  LibraryCallKit::generate_checkcast_arraycopy(const TypePtr* adr_type,
5204 5210                                               Node* dest_elem_klass,
5205 5211                                               Node* src,  Node* src_offset,
5206 5212                                               Node* dest, Node* dest_offset,
5207      -                                             Node* copy_length) {
     5213 +                                             Node* copy_length, bool need_pre_barrier) {
5208 5214    if (stopped())  return NULL;
5209 5215  
5210      -  address copyfunc_addr = StubRoutines::checkcast_arraycopy();
     5216 +  address copyfunc_addr = StubRoutines::checkcast_arraycopy(need_pre_barrier);
5211 5217    if (copyfunc_addr == NULL) { // Stub was not generated, go slow path.
5212 5218      return NULL;
5213 5219    }
5214 5220  
5215 5221    // Pick out the parameters required to perform a store-check
5216 5222    // for the target array.  This is an optimistic check.  It will
5217 5223    // look in each non-null element's class, at the desired klass's
5218 5224    // super_check_offset, for the desired klass.
5219 5225    int sco_offset = Klass::super_check_offset_offset_in_bytes() + sizeof(oopDesc);
5220 5226    Node* p3 = basic_plus_adr(dest_elem_klass, sco_offset);
↓ open down ↓ 40 lines elided ↑ open up ↑
5261 5267    return _gvn.transform(new (C, 1) ProjNode(call, TypeFunc::Parms));
5262 5268  }
5263 5269  
5264 5270  // Helper function; generates the fast out-of-line call to an arraycopy stub.
5265 5271  void
5266 5272  LibraryCallKit::generate_unchecked_arraycopy(const TypePtr* adr_type,
5267 5273                                               BasicType basic_elem_type,
5268 5274                                               bool disjoint_bases,
5269 5275                                               Node* src,  Node* src_offset,
5270 5276                                               Node* dest, Node* dest_offset,
5271      -                                             Node* copy_length) {
     5277 +                                             Node* copy_length, bool need_pre_barrier) {
5272 5278    if (stopped())  return;               // nothing to do
5273 5279  
5274 5280    Node* src_start  = src;
5275 5281    Node* dest_start = dest;
5276 5282    if (src_offset != NULL || dest_offset != NULL) {
5277 5283      assert(src_offset != NULL && dest_offset != NULL, "");
5278 5284      src_start  = array_element_address(src,  src_offset,  basic_elem_type);
5279 5285      dest_start = array_element_address(dest, dest_offset, basic_elem_type);
5280 5286    }
5281 5287  
5282 5288    // Figure out which arraycopy runtime method to call.
5283 5289    const char* copyfunc_name = "arraycopy";
5284 5290    address     copyfunc_addr =
5285 5291        basictype2arraycopy(basic_elem_type, src_offset, dest_offset,
5286      -                          disjoint_bases, copyfunc_name);
     5292 +                          disjoint_bases, copyfunc_name, need_pre_barrier);
5287 5293  
5288 5294    // Call it.  Note that the count_ix value is not scaled to a byte-size.
5289 5295    make_runtime_call(RC_LEAF|RC_NO_FP,
5290 5296                      OptoRuntime::fast_arraycopy_Type(),
5291 5297                      copyfunc_addr, copyfunc_name, adr_type,
5292 5298                      src_start, dest_start, copy_length XTOP);
5293 5299  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX