aboutsummaryrefslogtreecommitdiff
path: root/src/share
diff options
context:
space:
mode:
authornever <none@none>2010-01-15 11:53:33 -0800
committernever <none@none>2010-01-15 11:53:33 -0800
commit025714bc1f40750ed95cd0a795f057ee666d74e1 (patch)
tree4d027f0d1d843a2d3c8ffb1a175c90f0b2687d5e /src/share
parent76a8c2d50adc70f67a058d3c4322ec9f2ea8e52f (diff)
6849984: Value methods for platform dependent math functions constant fold incorrectly
Reviewed-by: kvn, twisti
Diffstat (limited to 'src/share')
-rw-r--r--src/share/vm/interpreter/abstractInterpreter.hpp4
-rw-r--r--src/share/vm/opto/subnode.cpp22
-rw-r--r--src/share/vm/runtime/compilationPolicy.cpp12
-rw-r--r--src/share/vm/runtime/stubRoutines.cpp10
-rw-r--r--src/share/vm/runtime/stubRoutines.hpp45
5 files changed, 75 insertions, 18 deletions
diff --git a/src/share/vm/interpreter/abstractInterpreter.hpp b/src/share/vm/interpreter/abstractInterpreter.hpp
index 78323ee2a..8ab9e40d3 100644
--- a/src/share/vm/interpreter/abstractInterpreter.hpp
+++ b/src/share/vm/interpreter/abstractInterpreter.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2010 Sun Microsystems, Inc. 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
@@ -109,6 +109,8 @@ class AbstractInterpreter: AllStatic {
static void print_method_kind(MethodKind kind) PRODUCT_RETURN;
+ static bool can_be_compiled(methodHandle m);
+
// Runtime support
// length = invoke bytecode length (to advance to next bytecode)
diff --git a/src/share/vm/opto/subnode.cpp b/src/share/vm/opto/subnode.cpp
index 81e033f27..1a8c2f60e 100644
--- a/src/share/vm/opto/subnode.cpp
+++ b/src/share/vm/opto/subnode.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2010 Sun Microsystems, Inc. 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
@@ -1244,8 +1244,7 @@ const Type *CosDNode::Value( PhaseTransform *phase ) const {
if( t1 == Type::TOP ) return Type::TOP;
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
double d = t1->getd();
- if( d < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dcos( d ) );
+ return TypeD::make( StubRoutines::intrinsic_cos( d ) );
}
//=============================================================================
@@ -1256,8 +1255,7 @@ const Type *SinDNode::Value( PhaseTransform *phase ) const {
if( t1 == Type::TOP ) return Type::TOP;
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
double d = t1->getd();
- if( d < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dsin( d ) );
+ return TypeD::make( StubRoutines::intrinsic_sin( d ) );
}
//=============================================================================
@@ -1268,8 +1266,7 @@ const Type *TanDNode::Value( PhaseTransform *phase ) const {
if( t1 == Type::TOP ) return Type::TOP;
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
double d = t1->getd();
- if( d < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dtan( d ) );
+ return TypeD::make( StubRoutines::intrinsic_tan( d ) );
}
//=============================================================================
@@ -1280,8 +1277,7 @@ const Type *LogDNode::Value( PhaseTransform *phase ) const {
if( t1 == Type::TOP ) return Type::TOP;
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
double d = t1->getd();
- if( d < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dlog( d ) );
+ return TypeD::make( StubRoutines::intrinsic_log( d ) );
}
//=============================================================================
@@ -1292,8 +1288,7 @@ const Type *Log10DNode::Value( PhaseTransform *phase ) const {
if( t1 == Type::TOP ) return Type::TOP;
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
double d = t1->getd();
- if( d < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dlog10( d ) );
+ return TypeD::make( StubRoutines::intrinsic_log10( d ) );
}
//=============================================================================
@@ -1304,8 +1299,7 @@ const Type *ExpDNode::Value( PhaseTransform *phase ) const {
if( t1 == Type::TOP ) return Type::TOP;
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
double d = t1->getd();
- if( d < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dexp( d ) );
+ return TypeD::make( StubRoutines::intrinsic_exp( d ) );
}
@@ -1323,5 +1317,5 @@ const Type *PowDNode::Value( PhaseTransform *phase ) const {
double d2 = t2->getd();
if( d1 < 0.0 ) return Type::DOUBLE;
if( d2 < 0.0 ) return Type::DOUBLE;
- return TypeD::make( SharedRuntime::dpow( d1, d2 ) );
+ return TypeD::make( StubRoutines::intrinsic_pow( d1, d2 ) );
}
diff --git a/src/share/vm/runtime/compilationPolicy.cpp b/src/share/vm/runtime/compilationPolicy.cpp
index ac870e0cc..2892ef123 100644
--- a/src/share/vm/runtime/compilationPolicy.cpp
+++ b/src/share/vm/runtime/compilationPolicy.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2000-2010 Sun Microsystems, Inc. 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
@@ -74,6 +74,16 @@ bool CompilationPolicy::canBeCompiled(methodHandle m) {
if (m->is_abstract()) return false;
if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false;
+ // Math intrinsics should never be compiled as this can lead to
+ // monotonicity problems because the interpreter will prefer the
+ // compiled code to the intrinsic version. This can't happen in
+ // production because the invocation counter can't be incremented
+ // but we shouldn't expose the system to this problem in testing
+ // modes.
+ if (!AbstractInterpreter::can_be_compiled(m)) {
+ return false;
+ }
+
return !m->is_not_compilable();
}
diff --git a/src/share/vm/runtime/stubRoutines.cpp b/src/share/vm/runtime/stubRoutines.cpp
index bdad678b0..25c02cd5f 100644
--- a/src/share/vm/runtime/stubRoutines.cpp
+++ b/src/share/vm/runtime/stubRoutines.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2010 Sun Microsystems, Inc. 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
@@ -97,6 +97,14 @@ address StubRoutines::_checkcast_arraycopy = NULL;
address StubRoutines::_unsafe_arraycopy = NULL;
address StubRoutines::_generic_arraycopy = NULL;
+double (* StubRoutines::_intrinsic_log )(double) = NULL;
+double (* StubRoutines::_intrinsic_log10 )(double) = NULL;
+double (* StubRoutines::_intrinsic_exp )(double) = NULL;
+double (* StubRoutines::_intrinsic_pow )(double, double) = NULL;
+double (* StubRoutines::_intrinsic_sin )(double) = NULL;
+double (* StubRoutines::_intrinsic_cos )(double) = NULL;
+double (* StubRoutines::_intrinsic_tan )(double) = NULL;
+
// Initialization
//
// Note: to break cycle with universe initialization, stubs are generated in two phases.
diff --git a/src/share/vm/runtime/stubRoutines.hpp b/src/share/vm/runtime/stubRoutines.hpp
index 677419164..2684f0475 100644
--- a/src/share/vm/runtime/stubRoutines.hpp
+++ b/src/share/vm/runtime/stubRoutines.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2010 Sun Microsystems, Inc. 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
@@ -148,6 +148,20 @@ class StubRoutines: AllStatic {
static address _unsafe_arraycopy;
static address _generic_arraycopy;
+ // These are versions of the java.lang.Math methods which perform
+ // the same operations as the intrinsic version. They are used for
+ // constant folding in the compiler to ensure equivalence. If the
+ // intrinsic version returns the same result as the strict version
+ // then they can be set to the appropriate function from
+ // SharedRuntime.
+ static double (*_intrinsic_log)(double);
+ static double (*_intrinsic_log10)(double);
+ static double (*_intrinsic_exp)(double);
+ static double (*_intrinsic_pow)(double, double);
+ static double (*_intrinsic_sin)(double);
+ static double (*_intrinsic_cos)(double);
+ static double (*_intrinsic_tan)(double);
+
public:
// Initialization/Testing
static void initialize1(); // must happen before universe::genesis
@@ -245,6 +259,35 @@ class StubRoutines: AllStatic {
static address unsafe_arraycopy() { return _unsafe_arraycopy; }
static address generic_arraycopy() { return _generic_arraycopy; }
+ static double intrinsic_log(double d) {
+ assert(_intrinsic_log != NULL, "must be defined");
+ return _intrinsic_log(d);
+ }
+ static double intrinsic_log10(double d) {
+ assert(_intrinsic_log != NULL, "must be defined");
+ return _intrinsic_log10(d);
+ }
+ static double intrinsic_exp(double d) {
+ assert(_intrinsic_exp != NULL, "must be defined");
+ return _intrinsic_exp(d);
+ }
+ static double intrinsic_pow(double d, double d2) {
+ assert(_intrinsic_pow != NULL, "must be defined");
+ return _intrinsic_pow(d, d2);
+ }
+ static double intrinsic_sin(double d) {
+ assert(_intrinsic_sin != NULL, "must be defined");
+ return _intrinsic_sin(d);
+ }
+ static double intrinsic_cos(double d) {
+ assert(_intrinsic_cos != NULL, "must be defined");
+ return _intrinsic_cos(d);
+ }
+ static double intrinsic_tan(double d) {
+ assert(_intrinsic_tan != NULL, "must be defined");
+ return _intrinsic_tan(d);
+ }
+
//
// Default versions of the above arraycopy functions for platforms which do
// not have specialized versions