Shark ldc improvements
Gary Benson
gbenson at redhat.com
Thu Jun 4 06:55:14 PDT 2009
Hi all,
This commit replaced the interpreter-style lookup of class and string
constants in ldc and friends with inlined oops using the code I wrote
yesterday. getfield and getstatic also use the code, for constant
fields, so they've been altered too, although the way HotSpot lays
things out means that getfield and getstatic never inline constants
(they get loaded from the object instead...)
Cheers,
Gary
--
http://gbenson.net/
-------------- next part --------------
diff -r 724f230eea38 ChangeLog
--- a/ChangeLog Wed Jun 03 11:15:36 2009 -0400
+++ b/ChangeLog Thu Jun 04 09:47:24 2009 -0400
@@ -1,3 +1,32 @@
+2009-06-04 Gary Benson <gbenson at redhat.com>
+
+ * ports/hotspot/src/share/vm/shark/sharkConstant.hpp: New file.
+ * ports/hotspot/src/share/vm/shark/sharkConstant.cpp: Likewise.
+
+ * ports/hotspot/src/share/vm/shark/sharkBlock.hpp
+ (SharkBlock::lookup_for_ldc): Removed.
+ (SharkBlock::do_ldc): Likewise.
+ * ports/hotspot/src/share/vm/shark/sharkBlock.cpp
+ (SharkBlock::parse_bytecode): Use new code for ldc and friends.
+ (SharkBlock::do_field_access): Use new code for constant fields.
+ (SharkBlock::lookup_for_ldc): Removed.
+
+ * ports/hotspot/src/share/vm/shark/sharkInliner.cpp
+ (SharkInlinerHelper::is_inlinable): Use new code for ldc and friends.
+ (SharkInlinerHelper::do_field_access): Use new code for constant fields.
+
+ * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
+ (SharkTopLevelBlock::lookup_for_ldc): Removed.
+ * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
+ (SharkTopLevelBlock::scan_for_traps): Use new code to for ldc and
+ constant field traps.
+ (SharkTopLevelBlock::lookup_for_ldc): Removed.
+
+ * ports/hotspot/src/share/vm/shark/sharkValue.hpp
+ (SharkValue::from_ciConstant): Removed.
+
+ * ports/hotspot/src/share/vm/includeDB_shark: Updated.
+
2009-06-03 Gary Benson <gbenson at redhat.com>
* ports/hotspot/src/share/vm/shark/sharkCodeBuffer.hpp:
diff -r 724f230eea38 ports/hotspot/src/share/vm/includeDB_shark
--- a/ports/hotspot/src/share/vm/includeDB_shark Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/includeDB_shark Thu Jun 04 09:47:24 2009 -0400
@@ -73,6 +73,7 @@
sharkBlock.cpp shark_globals.hpp
sharkBlock.cpp sharkBlock.hpp
sharkBlock.cpp sharkBuilder.hpp
+sharkBlock.cpp sharkConstant.hpp
sharkBlock.cpp sharkRuntime.hpp
sharkBlock.cpp sharkState.inline.hpp
sharkBlock.cpp sharkValue.hpp
@@ -83,6 +84,7 @@
sharkBlock.hpp debug.hpp
sharkBlock.hpp llvmHeaders.hpp
sharkBlock.hpp sharkBuilder.hpp
+sharkBlock.hpp sharkConstant.hpp
sharkBlock.hpp sharkState.hpp
sharkBlock.hpp sharkValue.hpp
@@ -158,6 +160,16 @@
sharkCompiler.hpp llvmHeaders.hpp
sharkCompiler.hpp sharkMemoryManager.hpp
+sharkConstant.cpp ciStreams.hpp
+sharkConstant.cpp sharkBuilder.hpp
+sharkConstant.cpp sharkConstant.hpp
+sharkConstant.cpp sharkValue.hpp
+
+sharkConstant.hpp allocation.hpp
+sharkConstant.hpp ciStreams.hpp
+sharkConstant.hpp sharkBuilder.hpp
+sharkConstant.hpp sharkValue.hpp
+
sharkConstantPool.cpp allocation.hpp
sharkConstantPool.cpp constantPoolOop.hpp
sharkConstantPool.cpp cpCacheOop.hpp
@@ -215,6 +227,7 @@
sharkInliner.cpp ciMethod.hpp
sharkInliner.cpp ciStreams.hpp
sharkInliner.cpp shark_globals.hpp
+sharkInliner.cpp sharkConstant.hpp
sharkInliner.cpp sharkInliner.hpp
sharkInliner.cpp sharkIntrinsics.hpp
sharkInliner.cpp sharkState.inline.hpp
@@ -302,6 +315,7 @@
sharkTopLevelBlock.cpp shark_globals.hpp
sharkTopLevelBlock.cpp sharkTopLevelBlock.hpp
sharkTopLevelBlock.cpp sharkBuilder.hpp
+sharkTopLevelBlock.cpp sharkConstant.hpp
sharkTopLevelBlock.cpp sharkConstantPool.hpp
sharkTopLevelBlock.cpp sharkInliner.hpp
sharkTopLevelBlock.cpp sharkRuntime.hpp
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkBlock.cpp
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.cpp Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.cpp Thu Jun 04 09:47:24 2009 -0400
@@ -163,7 +163,7 @@
case Bytecodes::_ldc:
case Bytecodes::_ldc_w:
case Bytecodes::_ldc2_w:
- do_ldc();
+ push(SharkConstant::for_ldc(iter())->value(builder()));
break;
case Bytecodes::_iload_0:
@@ -996,7 +996,9 @@
object = value->generic_value();
}
if (is_get && field->is_constant()) {
- value = SharkValue::from_ciConstant(field->constant_value());
+ SharkConstant *constant = SharkConstant::for_field(iter());
+ if (constant->is_loaded())
+ value = constant->value(builder());
}
if (!is_get || value == NULL) {
if (!is_field)
@@ -1163,11 +1165,6 @@
ShouldNotCallThis();
}
-Value* SharkBlock::lookup_for_ldc()
-{
- ShouldNotCallThis();
-}
-
Value* SharkBlock::lookup_for_field_access()
{
ShouldNotCallThis();
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkBlock.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.hpp Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.hpp Thu Jun 04 09:47:24 2009 -0400
@@ -202,7 +202,6 @@
// Helpers
protected:
virtual void do_zero_check(SharkValue* value);
- virtual llvm::Value* lookup_for_ldc();
virtual llvm::Value* lookup_for_field_access();
// Leaf calls
@@ -239,16 +238,6 @@
virtual int trap_request();
virtual int trap_bci();
virtual void do_trap(int trap_request);
-
- // ldc*
- private:
- void do_ldc()
- {
- SharkValue *value = SharkValue::from_ciConstant(iter()->get_constant());
- if (value == NULL)
- value = SharkValue::create_jobject(lookup_for_ldc(), true);
- push(value);
- }
// arraylength
protected:
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkConstant.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ports/hotspot/src/share/vm/shark/sharkConstant.cpp Thu Jun 04 09:47:24 2009 -0400
@@ -0,0 +1,121 @@
+/*
+ * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2009 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+
+#include "incls/_precompiled.incl"
+#include "incls/_sharkConstant.cpp.incl"
+
+using namespace llvm;
+
+SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter)
+{
+ return new SharkConstant(iter->get_constant(), NULL);
+}
+
+SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter)
+{
+ bool will_link;
+ ciField *field = iter->get_field(will_link);
+ assert(will_link, "typeflow responsibility");
+
+ return new SharkConstant(field->constant_value(), field->type());
+}
+
+SharkConstant::SharkConstant(ciConstant constant, ciType *type)
+{
+ SharkValue *value = NULL;
+
+ switch (constant.basic_type()) {
+ case T_BOOLEAN:
+ case T_BYTE:
+ case T_CHAR:
+ case T_SHORT:
+ case T_INT:
+ value = SharkValue::jint_constant(constant.as_int());
+ break;
+
+ case T_LONG:
+ value = SharkValue::jlong_constant(constant.as_long());
+ break;
+
+ case T_FLOAT:
+ value = SharkValue::jfloat_constant(constant.as_float());
+ break;
+
+ case T_DOUBLE:
+ value = SharkValue::jdouble_constant(constant.as_double());
+ break;
+
+ case T_OBJECT:
+ case T_ARRAY:
+ break;
+
+ case T_ILLEGAL:
+ // out of memory
+ _is_loaded = false;
+ return;
+
+ default:
+ tty->print_cr("Unhandled type %s", type2name(constant.basic_type()));
+ ShouldNotReachHere();
+ }
+
+ // Handle primitive types. We create SharkValues for these
+ // now; doing so doesn't emit any code, and it allows us to
+ // delegate a bunch of stuff to the SharkValue code.
+ if (value) {
+ _value = value;
+ _is_loaded = true;
+ _is_nonzero = value->zero_checked();
+ _is_two_word = value->is_two_word();
+ return;
+ }
+
+ // Handle reference types. This is tricky because some
+ // ciObjects are psuedo-objects that refer to oops which
+ // have yet to be created. We need to spot the unloaded
+ // objects (which differ between ldc* and get*, thanks!)
+ ciObject *object = constant.as_object();
+ if (object->is_klass()) {
+ // The constant returned for a klass is the ciKlass
+ // for the entry, but we want the java_mirror.
+ ciKlass *klass = object->as_klass();
+ if (!klass->is_loaded()) {
+ _is_loaded = false;
+ return;
+ }
+ object = klass->java_mirror();
+ }
+ if (object->is_null_object() || !object->has_encoding()) {
+ _is_loaded = false;
+ return;
+ }
+
+ _value = NULL;
+ _object = object;
+ _type = type ? type : ciType::make(T_OBJECT);
+ _is_loaded = true;
+ _is_nonzero = true;
+ _is_two_word = false;
+}
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkConstant.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ports/hotspot/src/share/vm/shark/sharkConstant.hpp Thu Jun 04 09:47:24 2009 -0400
@@ -0,0 +1,68 @@
+/*
+ * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2009 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+
+class SharkConstant : public ResourceObj {
+ public:
+ static SharkConstant* for_ldc(ciBytecodeStream* iter);
+ static SharkConstant* for_field(ciBytecodeStream* iter);
+
+ private:
+ SharkConstant(ciConstant constant, ciType* type);
+
+ private:
+ SharkValue* _value;
+ ciObject* _object;
+ ciType* _type;
+ bool _is_loaded;
+ bool _is_nonzero;
+ bool _is_two_word;
+
+ public:
+ bool is_loaded() const
+ {
+ return _is_loaded;
+ }
+ bool is_nonzero() const
+ {
+ assert(is_loaded(), "should be");
+ return _is_nonzero;
+ }
+ bool is_two_word() const
+ {
+ assert(is_loaded(), "should be");
+ return _is_two_word;
+ }
+
+ public:
+ SharkValue* value(SharkBuilder* builder)
+ {
+ assert(is_loaded(), "should be");
+ if (_value == NULL) {
+ _value = SharkValue::create_generic(
+ _type, builder->CreateInlineOop(_object), _is_nonzero);
+ }
+ return _value;
+ }
+};
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkInliner.cpp
--- a/ports/hotspot/src/share/vm/shark/sharkInliner.cpp Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkInliner.cpp Thu Jun 04 09:47:24 2009 -0400
@@ -267,7 +267,7 @@
ResourceMark rm;
initialize_for_check();
- SharkValue *sv;
+ SharkConstant *sc;
bool a, b, c, d;
iter()->reset_to_bci(0);
@@ -323,11 +323,11 @@
case Bytecodes::_ldc:
case Bytecodes::_ldc_w:
case Bytecodes::_ldc2_w:
- sv = SharkValue::from_ciConstant(iter()->get_constant());
- if (sv == NULL)
+ sc = SharkConstant::for_ldc(iter());
+ if (!sc->is_loaded())
return false;
- push(sv->zero_checked());
- if (sv->is_two_word())
+ push(sc->is_nonzero());
+ if (sc->is_two_word())
push(false);
break;
@@ -753,9 +753,9 @@
if (is_get) {
bool result_pushed = false;
if (field->is_constant()) {
- SharkValue *value = SharkValue::from_ciConstant(field->constant_value());
- if (value != NULL) {
- push(value->zero_checked());
+ SharkConstant *sc = SharkConstant::for_field(iter());
+ if (sc->is_loaded()) {
+ push(sc->is_nonzero());
result_pushed = true;
}
}
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp Thu Jun 04 09:47:24 2009 -0400
@@ -48,7 +48,7 @@
switch (bc()) {
case Bytecodes::_ldc:
case Bytecodes::_ldc_w:
- if (iter()->is_unresolved_string() || iter()->is_unresolved_klass()) {
+ if (!SharkConstant::for_ldc(iter())->is_loaded()) {
set_trap(
Deoptimization::make_trap_request(
Deoptimization::Reason_uninitialized,
@@ -80,10 +80,9 @@
if (is_field)
break;
- // There won't be a pool access if this is a getstatic that
- // resolves to a handled constant either
+ // There won't be a pool access if this is a constant getstatic
if (bc() == Bytecodes::_getstatic && field->is_constant()) {
- if (SharkValue::from_ciConstant(field->constant_value()))
+ if (SharkConstant::for_field(iter())->is_loaded())
break;
}
@@ -607,37 +606,6 @@
}
builder()->CreateRetVoid();
-}
-
-Value *SharkTopLevelBlock::lookup_for_ldc()
-{
- int index = iter()->get_constant_index();
- constantTag tag = target()->holder()->constant_pool_tag_at(index);
-
- SharkConstantPool constants(this);
- Value *entry = constants.object_at(index);
-
- Value *klass_part;
- switch (tag.value()) {
- case JVM_CONSTANT_String:
- return entry;
-
- case JVM_CONSTANT_Class:
- klass_part = builder()->CreateAddressOfStructEntry(
- entry,
- in_ByteSize(klassOopDesc::klass_part_offset_in_bytes()),
- SharkType::klass_type(),
- "klass_part");
- // XXX FIXME: We need a memory barrier before this load
- return builder()->CreateValueOfStructEntry(
- klass_part,
- in_ByteSize(Klass::java_mirror_offset_in_bytes()),
- SharkType::oop_type(),
- "java_mirror");
-
- default:
- ShouldNotReachHere();
- }
}
Value* SharkTopLevelBlock::lookup_for_field_access()
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp Thu Jun 04 09:47:24 2009 -0400
@@ -222,7 +222,6 @@
// Helpers
private:
- llvm::Value* lookup_for_ldc();
llvm::Value* lookup_for_field_access();
void do_branch(int successor_index);
diff -r 724f230eea38 ports/hotspot/src/share/vm/shark/sharkValue.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkValue.hpp Wed Jun 03 11:15:36 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkValue.hpp Thu Jun 04 09:47:24 2009 -0400
@@ -145,45 +145,6 @@
return create_jobject(LLVMValue::null(), false);
}
static inline SharkValue* address_constant(int bci);
-
- // Typed conversion from HotSpot ciConstants
- public:
- static SharkValue* from_ciConstant(ciConstant value)
- {
- switch (value.basic_type()) {
- case T_BOOLEAN:
- return SharkValue::jint_constant(value.as_boolean());
-
- case T_BYTE:
- return SharkValue::jint_constant(value.as_byte());
-
- case T_CHAR:
- return SharkValue::jint_constant(value.as_char());
-
- case T_SHORT:
- return SharkValue::jint_constant(value.as_short());
-
- case T_INT:
- return SharkValue::jint_constant(value.as_int());
-
- case T_LONG:
- return SharkValue::jlong_constant(value.as_long());
-
- case T_FLOAT:
- return SharkValue::jfloat_constant(value.as_float());
-
- case T_DOUBLE:
- return SharkValue::jdouble_constant(value.as_double());
-
- case T_OBJECT:
- case T_ARRAY:
- return NULL;
-
- default:
- tty->print_cr("Unhandled type %s", type2name(value.basic_type()));
- ShouldNotReachHere();
- }
- }
// Type-losing conversions -- use with care!
public:
More information about the zero-dev
mailing list