/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_RUNTIME_SIGNATURE_HPP
#define SHARE_VM_RUNTIME_SIGNATURE_HPP
#include "memory/allocation.hpp"
#include "oops/methodOop.hpp"
// SignatureIterators iterate over a Java signature (or parts of it).
// (Syntax according to: "The Java Virtual Machine Specification" by
// Tim Lindholm & Frank Yellin; section 4.3 Descriptors; p. 89ff.)
//
// Example: Iterating over ([Lfoo;D)I using
// 0123456789
//
// iterate_parameters() calls: do_array(2, 7); do_double();
// iterate_returntype() calls: do_int();
// iterate() calls: do_array(2, 7); do_double(); do_int();
//
// is_return_type() is: false ; false ; true
//
// NOTE: The new optimizer has an alternate, for-loop based signature
protected:
void expect(char c);
void skip_optional_size();
int parse_type(); // returns the parameter size in words (0 for void)
void check_signature_end();
public:
// Definitions used in generating and iterating the
// bit field form of the signature generated by the
// Fingerprinter.
enum {
// max parameters is wordsize minus
// The sign bit, termination field, the result and static bit fields
};
// Constructors
// Iteration
void dispatch_field(); // dispatches once for field signatures
void iterate_parameters(); // iterates over parameters only
void iterate_returntype(); // iterates over returntype only
void iterate(); // iterates over whole signature
// Returns the word index of the current parameter;
// Basic types
virtual void do_bool () = 0;
virtual void do_char () = 0;
virtual void do_float () = 0;
virtual void do_double() = 0;
virtual void do_byte () = 0;
virtual void do_short () = 0;
virtual void do_int () = 0;
virtual void do_long () = 0;
virtual void do_void () = 0;
// Object types (begin indexes the first character of the entry, end indexes the first character after the entry)
};
// Specialized SignatureIterators: Used to compute signature specific values.
protected:
public:
};
protected:
bool _has_iterated_return;
int _size;
void lazy_iterate_parameters() { if (!_has_iterated) { iterate_parameters(); _has_iterated = true; } }
void lazy_iterate_return() { if (!_has_iterated_return) { iterate_returntype(); _has_iterated_return = true; } }
public:
_has_iterated = _has_iterated_return = false;
_size = 0;
}
};
// Specialized SignatureIterator: Used to compute the argument size.
private:
public:
};
private:
public:
};
// Specialized SignatureIterator: Used to compute the result type.
private:
public:
};
// Fingerprinter computes a unique ID for a given method. The ID
// is a bitvector characterizing the methods signature (incl. the receiver).
private:
int _shift_count;
public:
void do_bool() { _fingerprint |= (((uint64_t)bool_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_char() { _fingerprint |= (((uint64_t)char_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_byte() { _fingerprint |= (((uint64_t)byte_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_short() { _fingerprint |= (((uint64_t)short_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_int() { _fingerprint |= (((uint64_t)int_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_long() { _fingerprint |= (((uint64_t)long_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_float() { _fingerprint |= (((uint64_t)float_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_double() { _fingerprint |= (((uint64_t)double_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_object(int begin, int end) { _fingerprint |= (((uint64_t)obj_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_array (int begin, int end) { _fingerprint |= (((uint64_t)obj_parm) << _shift_count); _shift_count += parameter_feature_size; }
_fingerprint = 0;
}
// See if we fingerprinted this method already
}
return _fingerprint;
}
return _fingerprint;
}
};
// Specialized SignatureIterator: Used for native call purposes
private:
// We need separate JNI and Java offset values because in 64 bit mode,
// the argument offsets are not in sync with the Java stack.
// For example a long takes up 1 "C" stack entry but 2 Java stack entries.
#ifdef _LP64
#else
#endif
#ifdef _LP64
#else
#endif
public:
// int java_offset() const { return method()->size_of_parameters() - _offset - 1; }
virtual void pass_int() = 0;
virtual void pass_long() = 0;
virtual void pass_object() = 0;
virtual void pass_float() = 0;
#ifdef _LP64
virtual void pass_double() = 0;
#else
#endif
_offset = 0;
_jni_offset = 0;
}
// iterate() calles the 2 virtual methods according to the following invocation syntax:
//
// {pass_int | pass_long | pass_object}
//
// Arguments are handled from left to right (receiver first, if any).
// The offset() values refer to the Java stack offsets but are 0 based and increasing.
// The java_offset() values count down to 0, and refer to the Java TOS.
// The jni_offset() values increase from 1 or 2, and refer to C arguments.
}
// Optimized path if we have the bitvector form of signature
if (!is_static()) {
// handle receiver (not handled by iterate because not in signature)
}
}
};
// Handy stream for iterating over signature
private:
int _begin;
int _end;
bool _at_return_type;
public:
bool is_done() const;
void next_non_primitive(int t);
void next() {
return;
}
switch (t) {
default : next_non_primitive(t);
return;
}
_end++;
}
~SignatureStream();
bool is_object() const; // True if this argument is an object
bool is_array() const; // True if this argument is an array
// return same as_symbol except allocation of new symbols is avoided.
};
public:
// Returns true if the symbol is valid method or type signature
private:
static bool invalid_name_char(char);
};
#endif // SHARE_VM_RUNTIME_SIGNATURE_HPP