hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp
changeset 35479 62c12ca7a45e
parent 35214 d86005e0b4c2
child 36181 3a16e8ce0abf
equal deleted inserted replaced
35474:8333d76c7fee 35479:62c12ca7a45e
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
     3  * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     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
     7  * under the terms of the GNU General Public License version 2 only, as
   745   istate->set_stack_limit(stack->sp() - 1);
   745   istate->set_stack_limit(stack->sp() - 1);
   746 
   746 
   747   return (InterpreterFrame *) fp;
   747   return (InterpreterFrame *) fp;
   748 }
   748 }
   749 
   749 
   750 int AbstractInterpreter::BasicType_as_index(BasicType type) {
   750 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
   751   int i = 0;
   751   ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
   752   switch (type) {
   752 
   753     case T_BOOLEAN: i = 0; break;
   753   int size_in_words = size >> LogBytesPerWord;
   754     case T_CHAR   : i = 1; break;
   754   assert(size_in_words * wordSize == size, "unaligned");
   755     case T_BYTE   : i = 2; break;
   755   assert(size_in_words >= header_words, "too small");
   756     case T_SHORT  : i = 3; break;
   756   stack->overflow_check(size_in_words, CHECK_NULL);
   757     case T_INT    : i = 4; break;
   757 
   758     case T_LONG   : i = 5; break;
   758   stack->push(0); // next_frame, filled in later
   759     case T_VOID   : i = 6; break;
   759   intptr_t *fp = stack->sp();
   760     case T_FLOAT  : i = 7; break;
   760   assert(fp - stack->sp() == next_frame_off, "should be");
   761     case T_DOUBLE : i = 8; break;
   761 
   762     case T_OBJECT : i = 9; break;
   762   stack->push(INTERPRETER_FRAME);
   763     case T_ARRAY  : i = 9; break;
   763   assert(fp - stack->sp() == frame_type_off, "should be");
   764     default       : ShouldNotReachHere();
   764 
   765   }
   765   interpreterState istate =
   766   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
   766     (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
   767          "index out of bounds");
   767   assert(fp - stack->sp() == istate_off, "should be");
   768   return i;
   768   istate->set_self_link(NULL); // mark invalid
       
   769 
       
   770   stack->alloc((size_in_words - header_words) * wordSize);
       
   771 
       
   772   return (InterpreterFrame *) fp;
   769 }
   773 }
   770 
   774 
   771 BasicType CppInterpreter::result_type_of(Method* method) {
   775 BasicType CppInterpreter::result_type_of(Method* method) {
   772   BasicType t;
   776   BasicType t;
   773   switch (method->result_index()) {
   777   switch (method->result_index()) {
   786   assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(),
   790   assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(),
   787          "out of step with AbstractInterpreter::BasicType_as_index");
   791          "out of step with AbstractInterpreter::BasicType_as_index");
   788   return t;
   792   return t;
   789 }
   793 }
   790 
   794 
   791 address CppInterpreterGenerator::generate_empty_entry() {
       
   792   if (!UseFastEmptyMethods)
       
   793     return NULL;
       
   794 
       
   795   return generate_entry((address) CppInterpreter::empty_entry);
       
   796 }
       
   797 
       
   798 address CppInterpreterGenerator::generate_accessor_entry() {
       
   799   if (!UseFastAccessorMethods)
       
   800     return NULL;
       
   801 
       
   802   return generate_entry((address) CppInterpreter::accessor_entry);
       
   803 }
       
   804 
       
   805 address CppInterpreterGenerator::generate_Reference_get_entry(void) {
       
   806 #if INCLUDE_ALL_GCS
       
   807   if (UseG1GC) {
       
   808     // We need to generate have a routine that generates code to:
       
   809     //   * load the value in the referent field
       
   810     //   * passes that value to the pre-barrier.
       
   811     //
       
   812     // In the case of G1 this will record the value of the
       
   813     // referent in an SATB buffer if marking is active.
       
   814     // This will cause concurrent marking to mark the referent
       
   815     // field as live.
       
   816     Unimplemented();
       
   817   }
       
   818 #endif // INCLUDE_ALL_GCS
       
   819 
       
   820   // If G1 is not enabled then attempt to go through the normal entry point
       
   821   // Reference.get could be instrumented by jvmti
       
   822   return NULL;
       
   823 }
       
   824 
       
   825 address CppInterpreterGenerator::generate_native_entry(bool synchronized) {
       
   826   return generate_entry((address) CppInterpreter::native_entry);
       
   827 }
       
   828 
       
   829 address CppInterpreterGenerator::generate_normal_entry(bool synchronized) {
       
   830   return generate_entry((address) CppInterpreter::normal_entry);
       
   831 }
       
   832 
       
   833 
       
   834 // Deoptimization helpers
       
   835 
       
   836 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
       
   837   ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
       
   838 
       
   839   int size_in_words = size >> LogBytesPerWord;
       
   840   assert(size_in_words * wordSize == size, "unaligned");
       
   841   assert(size_in_words >= header_words, "too small");
       
   842   stack->overflow_check(size_in_words, CHECK_NULL);
       
   843 
       
   844   stack->push(0); // next_frame, filled in later
       
   845   intptr_t *fp = stack->sp();
       
   846   assert(fp - stack->sp() == next_frame_off, "should be");
       
   847 
       
   848   stack->push(INTERPRETER_FRAME);
       
   849   assert(fp - stack->sp() == frame_type_off, "should be");
       
   850 
       
   851   interpreterState istate =
       
   852     (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
       
   853   assert(fp - stack->sp() == istate_off, "should be");
       
   854   istate->set_self_link(NULL); // mark invalid
       
   855 
       
   856   stack->alloc((size_in_words - header_words) * wordSize);
       
   857 
       
   858   return (InterpreterFrame *) fp;
       
   859 }
       
   860 
       
   861 int AbstractInterpreter::size_activation(int       max_stack,
       
   862                                          int       tempcount,
       
   863                                          int       extra_args,
       
   864                                          int       moncount,
       
   865                                          int       callee_param_count,
       
   866                                          int       callee_locals,
       
   867                                          bool      is_top_frame) {
       
   868   int header_words        = InterpreterFrame::header_words;
       
   869   int monitor_words       = moncount * frame::interpreter_frame_monitor_size();
       
   870   int stack_words         = is_top_frame ? max_stack : tempcount;
       
   871   int callee_extra_locals = callee_locals - callee_param_count;
       
   872 
       
   873   return header_words + monitor_words + stack_words + callee_extra_locals;
       
   874 }
       
   875 
       
   876 void AbstractInterpreter::layout_activation(Method* method,
       
   877                                             int       tempcount,
       
   878                                             int       popframe_extra_args,
       
   879                                             int       moncount,
       
   880                                             int       caller_actual_parameters,
       
   881                                             int       callee_param_count,
       
   882                                             int       callee_locals,
       
   883                                             frame*    caller,
       
   884                                             frame*    interpreter_frame,
       
   885                                             bool      is_top_frame,
       
   886                                             bool      is_bottom_frame) {
       
   887   assert(popframe_extra_args == 0, "what to do?");
       
   888   assert(!is_top_frame || (!callee_locals && !callee_param_count),
       
   889          "top frame should have no caller");
       
   890 
       
   891   // This code must exactly match what InterpreterFrame::build
       
   892   // does (the full InterpreterFrame::build, that is, not the
       
   893   // one that creates empty frames for the deoptimizer).
       
   894   //
       
   895   // interpreter_frame will be filled in.  It's size is determined by
       
   896   // a previous call to the size_activation() method,
       
   897   //
       
   898   // Note that tempcount is the current size of the expression
       
   899   // stack.  For top most frames we will allocate a full sized
       
   900   // expression stack and not the trimmed version that non-top
       
   901   // frames have.
       
   902 
       
   903   int monitor_words       = moncount * frame::interpreter_frame_monitor_size();
       
   904   intptr_t *locals        = interpreter_frame->fp() + method->max_locals();
       
   905   interpreterState istate = interpreter_frame->get_interpreterState();
       
   906   intptr_t *monitor_base  = (intptr_t*) istate;
       
   907   intptr_t *stack_base    = monitor_base - monitor_words;
       
   908   intptr_t *stack         = stack_base - tempcount - 1;
       
   909 
       
   910   BytecodeInterpreter::layout_interpreterState(istate,
       
   911                                                caller,
       
   912                                                NULL,
       
   913                                                method,
       
   914                                                locals,
       
   915                                                stack,
       
   916                                                stack_base,
       
   917                                                monitor_base,
       
   918                                                NULL,
       
   919                                                is_top_frame);
       
   920 }
       
   921 
       
   922 void BytecodeInterpreter::layout_interpreterState(interpreterState istate,
       
   923                                                   frame*    caller,
       
   924                                                   frame*    current,
       
   925                                                   Method* method,
       
   926                                                   intptr_t* locals,
       
   927                                                   intptr_t* stack,
       
   928                                                   intptr_t* stack_base,
       
   929                                                   intptr_t* monitor_base,
       
   930                                                   intptr_t* frame_bottom,
       
   931                                                   bool      is_top_frame) {
       
   932   istate->set_locals(locals);
       
   933   istate->set_method(method);
       
   934   istate->set_self_link(istate);
       
   935   istate->set_prev_link(NULL);
       
   936   // thread will be set by a hacky repurposing of frame::patch_pc()
       
   937   // bcp will be set by vframeArrayElement::unpack_on_stack()
       
   938   istate->set_constants(method->constants()->cache());
       
   939   istate->set_msg(BytecodeInterpreter::method_resume);
       
   940   istate->set_bcp_advance(0);
       
   941   istate->set_oop_temp(NULL);
       
   942   istate->set_mdx(NULL);
       
   943   if (caller->is_interpreted_frame()) {
       
   944     interpreterState prev = caller->get_interpreterState();
       
   945     prev->set_callee(method);
       
   946     if (*prev->bcp() == Bytecodes::_invokeinterface)
       
   947       prev->set_bcp_advance(5);
       
   948     else
       
   949       prev->set_bcp_advance(3);
       
   950   }
       
   951   istate->set_callee(NULL);
       
   952   istate->set_monitor_base((BasicObjectLock *) monitor_base);
       
   953   istate->set_stack_base(stack_base);
       
   954   istate->set_stack(stack);
       
   955   istate->set_stack_limit(stack_base - method->max_stack() - 1);
       
   956 }
       
   957 
       
   958 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
   795 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
   959   ShouldNotCallThis();
   796   ShouldNotCallThis();
   960   return NULL;
   797   return NULL;
   961 }
   798 }
   962 
   799 
   963 address CppInterpreter::deopt_entry(TosState state, int length) {
   800 address CppInterpreter::deopt_entry(TosState state, int length) {
   964   return NULL;
   801   return NULL;
   965 }
   802 }
   966 
   803 
   967 // Helper for (runtime) stack overflow checks
       
   968 
       
   969 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
       
   970   return 0;
       
   971 }
       
   972 
       
   973 // Helper for figuring out if frames are interpreter frames
   804 // Helper for figuring out if frames are interpreter frames
   974 
   805 
   975 bool CppInterpreter::contains(address pc) {
   806 bool CppInterpreter::contains(address pc) {
   976   return false; // make frame::print_value_on work
   807   return false; // make frame::print_value_on work
   977 }
   808 }