1 /* 2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2007, 2008 Red Hat, Inc. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef CPU_ZERO_INTERPRETERRT_ZERO_HPP 27 #define CPU_ZERO_INTERPRETERRT_ZERO_HPP 28 29 // This is included in the middle of class Interpreter. 30 // Do not include files here. 31 32 33 class SignatureHandler { 34 public: from_handlerAddr(address handlerAddr)35 static SignatureHandler *from_handlerAddr(address handlerAddr) { 36 return (SignatureHandler *) handlerAddr; 37 } 38 39 public: cif() const40 ffi_cif* cif() const { 41 return (ffi_cif *) this; 42 } 43 argument_count() const44 int argument_count() const { 45 return cif()->nargs; 46 } 47 argument_types() const48 ffi_type** argument_types() const { 49 return (ffi_type**) (cif() + 1); 50 } 51 argument_type(int i) const52 ffi_type* argument_type(int i) const { 53 return argument_types()[i]; 54 } 55 result_type() const56 ffi_type* result_type() const { 57 return *(argument_types() + argument_count()); 58 } 59 60 protected: 61 friend class InterpreterRuntime; 62 friend class SignatureHandlerLibrary; 63 64 void finalize(); 65 }; 66 67 class SignatureHandlerGeneratorBase : public NativeSignatureIterator { 68 private: 69 ffi_cif* _cif; 70 71 protected: SignatureHandlerGeneratorBase(const methodHandle & method,ffi_cif * cif)72 SignatureHandlerGeneratorBase(const methodHandle& method, ffi_cif *cif) 73 : NativeSignatureIterator(method), _cif(cif) { 74 _cif->nargs = 0; 75 } 76 cif() const77 ffi_cif *cif() const { 78 return _cif; 79 } 80 81 public: 82 void generate(uint64_t fingerprint); 83 84 private: 85 void pass_int(); 86 void pass_long(); 87 void pass_float(); 88 void pass_double(); 89 void pass_object(); 90 91 private: 92 void push(BasicType type); 93 virtual void push(intptr_t value) = 0; 94 }; 95 96 class SignatureHandlerGenerator : public SignatureHandlerGeneratorBase { 97 private: 98 CodeBuffer* _cb; 99 100 public: SignatureHandlerGenerator(const methodHandle & method,CodeBuffer * buffer)101 SignatureHandlerGenerator(const methodHandle& method, CodeBuffer* buffer) 102 : SignatureHandlerGeneratorBase(method, (ffi_cif *) buffer->insts_end()), 103 _cb(buffer) { 104 _cb->set_insts_end((address) (cif() + 1)); 105 } 106 107 private: push(intptr_t value)108 void push(intptr_t value) { 109 intptr_t *dst = (intptr_t *) _cb->insts_end(); 110 _cb->set_insts_end((address) (dst + 1)); 111 *dst = value; 112 } 113 }; 114 115 class SlowSignatureHandlerGenerator : public SignatureHandlerGeneratorBase { 116 private: 117 intptr_t *_dst; 118 119 public: SlowSignatureHandlerGenerator(const methodHandle & method,intptr_t * buf)120 SlowSignatureHandlerGenerator(const methodHandle& method, intptr_t* buf) 121 : SignatureHandlerGeneratorBase(method, (ffi_cif *) buf) { 122 _dst = (intptr_t *) (cif() + 1); 123 } 124 125 private: push(intptr_t value)126 void push(intptr_t value) { 127 *(_dst++) = value; 128 } 129 130 public: handler() const131 SignatureHandler *handler() const { 132 return (SignatureHandler *) cif(); 133 } 134 }; 135 136 #endif // CPU_ZERO_INTERPRETERRT_ZERO_HPP 137