1 /*
2 * Copyright (c) 2005, 2018, 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 *
1701 null_check_info = new CodeEmitInfo(range_check_info);
1702 }
1703
1704 if (GenerateRangeChecks && needs_range_check) {
1705 if (use_length) {
1706 __ cmp(lir_cond_belowEqual, length.result(), index.result());
1707 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result(), array.result()));
1708 } else {
1709 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
1710 // range_check also does the null check
1711 null_check_info = NULL;
1712 }
1713 }
1714
1715 if (GenerateArrayStoreCheck && needs_store_check) {
1716 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
1717 array_store_check(value.result(), array.result(), store_check_info, x->profiled_method(), x->profiled_bci());
1718 }
1719
1720 if (is_loaded_flattened_array) {
1721 index.load_item();
1722 access_flattened_array(false, array, index, value);
1723 } else {
1724 StoreFlattenedArrayStub* slow_path = NULL;
1725
1726 if (x->array()->maybe_flattened_array()) {
1727 // Check if we indeed have a flattened array
1728 index.load_item();
1729 slow_path = new StoreFlattenedArrayStub(array.result(), index.result(), value.result(), state_for(x));
1730 check_flattened_array(array, slow_path);
1731 }
1732
1733 DecoratorSet decorators = IN_HEAP | IS_ARRAY;
1734 if (x->check_boolean()) {
1735 decorators |= C1_MASK_BOOLEAN;
1736 }
1737
1738 access_store_at(decorators, x->elt_type(), array, index.result(), value.result(),
1739 NULL, null_check_info);
1740 if (slow_path != NULL) {
1741 __ branch_destination(slow_path->continuation());
1974 __ null_check(obj, new CodeEmitInfo(info));
1975 }
1976 }
1977 __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none);
1978 }
1979
1980
1981 void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {
1982 bool use_length = x->length() != NULL;
1983 LIRItem array(x->array(), this);
1984 LIRItem index(x->index(), this);
1985 LIRItem length(this);
1986 bool needs_range_check = x->compute_needs_range_check();
1987
1988 if (use_length && needs_range_check) {
1989 length.set_instruction(x->length());
1990 length.load_item();
1991 }
1992
1993 array.load_item();
1994 if (index.is_constant() && can_inline_as_constant(x->index())
1995 && !x->array()->maybe_flattened_array()) {
1996 // let it be a constant
1997 index.dont_load_item();
1998 } else {
1999 index.load_item();
2000 }
2001
2002 CodeEmitInfo* range_check_info = state_for(x);
2003 CodeEmitInfo* null_check_info = NULL;
2004 if (x->needs_null_check()) {
2005 NullCheck* nc = x->explicit_null_check();
2006 if (nc != NULL) {
2007 null_check_info = state_for(nc);
2008 } else {
2009 null_check_info = range_check_info;
2010 }
2011 if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {
2012 LIR_Opr obj = new_register(T_OBJECT);
2013 __ move(LIR_OprFact::oopConst(NULL), obj);
2014 __ null_check(obj, new CodeEmitInfo(null_check_info));
2015 }
2025 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result(), array.result()));
2026 } else {
2027 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
2028 // The range check performs the null check, so clear it out for the load
2029 null_check_info = NULL;
2030 }
2031 }
2032
2033 if (x->array()->is_loaded_flattened_array()) {
2034 // Find the destination address (of the NewValueTypeInstance)
2035 LIR_Opr obj = x->vt()->operand();
2036 LIRItem obj_item(x->vt(), this);
2037
2038 access_flattened_array(true, array, index, obj_item);
2039 set_no_result(x);
2040 } else {
2041 LIR_Opr result = rlock_result(x, x->elt_type());
2042 LoadFlattenedArrayStub* slow_path = NULL;
2043
2044 if (x->array()->maybe_flattened_array()) {
2045 // Check if we indeed have a flattened array
2046 slow_path = new LoadFlattenedArrayStub(array.result(), index.result(), result, state_for(x));
2047 check_flattened_array(array, slow_path);
2048 }
2049
2050 DecoratorSet decorators = IN_HEAP | IS_ARRAY;
2051 access_load_at(decorators, x->elt_type(),
2052 array, index.result(), result,
2053 NULL, null_check_info);
2054
2055 if (slow_path != NULL) {
2056 __ branch_destination(slow_path->continuation());
2057 }
2058 }
2059 }
2060
2061
2062 void LIRGenerator::do_NullCheck(NullCheck* x) {
2063 if (x->can_trap()) {
2064 LIRItem value(x->obj(), this);
|
1 /*
2 * Copyright (c) 2005, 2019, 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 *
1701 null_check_info = new CodeEmitInfo(range_check_info);
1702 }
1703
1704 if (GenerateRangeChecks && needs_range_check) {
1705 if (use_length) {
1706 __ cmp(lir_cond_belowEqual, length.result(), index.result());
1707 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result(), array.result()));
1708 } else {
1709 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
1710 // range_check also does the null check
1711 null_check_info = NULL;
1712 }
1713 }
1714
1715 if (GenerateArrayStoreCheck && needs_store_check) {
1716 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
1717 array_store_check(value.result(), array.result(), store_check_info, x->profiled_method(), x->profiled_bci());
1718 }
1719
1720 if (is_loaded_flattened_array) {
1721 if (!x->is_exact_flattened_array_store()) {
1722 CodeEmitInfo* info = new CodeEmitInfo(range_check_info);
1723 ciKlass* element_klass = x->array()->declared_type()->as_value_array_klass()->element_klass();
1724 flattened_array_store_check(value.result(), element_klass, info);
1725 }
1726 access_flattened_array(false, array, index, value);
1727 } else {
1728 StoreFlattenedArrayStub* slow_path = NULL;
1729
1730 if (x->array()->maybe_flattened_array()) {
1731 // Check if we indeed have a flattened array
1732 index.load_item();
1733 slow_path = new StoreFlattenedArrayStub(array.result(), index.result(), value.result(), state_for(x));
1734 check_flattened_array(array, slow_path);
1735 }
1736
1737 DecoratorSet decorators = IN_HEAP | IS_ARRAY;
1738 if (x->check_boolean()) {
1739 decorators |= C1_MASK_BOOLEAN;
1740 }
1741
1742 access_store_at(decorators, x->elt_type(), array, index.result(), value.result(),
1743 NULL, null_check_info);
1744 if (slow_path != NULL) {
1745 __ branch_destination(slow_path->continuation());
1978 __ null_check(obj, new CodeEmitInfo(info));
1979 }
1980 }
1981 __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none);
1982 }
1983
1984
1985 void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {
1986 bool use_length = x->length() != NULL;
1987 LIRItem array(x->array(), this);
1988 LIRItem index(x->index(), this);
1989 LIRItem length(this);
1990 bool needs_range_check = x->compute_needs_range_check();
1991
1992 if (use_length && needs_range_check) {
1993 length.set_instruction(x->length());
1994 length.load_item();
1995 }
1996
1997 array.load_item();
1998 if (index.is_constant() && can_inline_as_constant(x->index())) {
1999 // let it be a constant
2000 index.dont_load_item();
2001 } else {
2002 index.load_item();
2003 }
2004
2005 CodeEmitInfo* range_check_info = state_for(x);
2006 CodeEmitInfo* null_check_info = NULL;
2007 if (x->needs_null_check()) {
2008 NullCheck* nc = x->explicit_null_check();
2009 if (nc != NULL) {
2010 null_check_info = state_for(nc);
2011 } else {
2012 null_check_info = range_check_info;
2013 }
2014 if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {
2015 LIR_Opr obj = new_register(T_OBJECT);
2016 __ move(LIR_OprFact::oopConst(NULL), obj);
2017 __ null_check(obj, new CodeEmitInfo(null_check_info));
2018 }
2028 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result(), array.result()));
2029 } else {
2030 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
2031 // The range check performs the null check, so clear it out for the load
2032 null_check_info = NULL;
2033 }
2034 }
2035
2036 if (x->array()->is_loaded_flattened_array()) {
2037 // Find the destination address (of the NewValueTypeInstance)
2038 LIR_Opr obj = x->vt()->operand();
2039 LIRItem obj_item(x->vt(), this);
2040
2041 access_flattened_array(true, array, index, obj_item);
2042 set_no_result(x);
2043 } else {
2044 LIR_Opr result = rlock_result(x, x->elt_type());
2045 LoadFlattenedArrayStub* slow_path = NULL;
2046
2047 if (x->array()->maybe_flattened_array()) {
2048 index.load_item();
2049 // Check if we indeed have a flattened array
2050 slow_path = new LoadFlattenedArrayStub(array.result(), index.result(), result, state_for(x));
2051 check_flattened_array(array, slow_path);
2052 }
2053
2054 DecoratorSet decorators = IN_HEAP | IS_ARRAY;
2055 access_load_at(decorators, x->elt_type(),
2056 array, index.result(), result,
2057 NULL, null_check_info);
2058
2059 if (slow_path != NULL) {
2060 __ branch_destination(slow_path->continuation());
2061 }
2062 }
2063 }
2064
2065
2066 void LIRGenerator::do_NullCheck(NullCheck* x) {
2067 if (x->can_trap()) {
2068 LIRItem value(x->obj(), this);
|