hotspot/src/share/vm/shark/sharkCodeBuffer.hpp
author never
Sun, 11 Sep 2011 14:48:24 -0700
changeset 10547 ea4a2ec31ae2
parent 7397 5b173b4ca846
child 14622 8e94e4186d35
permissions -rw-r--r--
7088955: add C2 IR support to the SA Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
     2
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     3
 * Copyright 2009 Red Hat, Inc.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     5
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     8
 * published by the Free Software Foundation.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     9
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    14
 * accompanied this code).
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    15
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    19
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    22
 * questions.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    23
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    24
 */
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    25
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    26
#ifndef SHARE_VM_SHARK_SHARKCODEBUFFER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    27
#define SHARE_VM_SHARK_SHARKCODEBUFFER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    28
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    29
#include "asm/codeBuffer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    30
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    31
#include "shark/llvmHeaders.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    32
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    33
class SharkCodeBuffer : public StackObj {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    34
 public:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    35
  SharkCodeBuffer(MacroAssembler* masm)
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    36
    : _masm(masm), _base_pc(NULL) {}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    37
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    38
 private:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    39
  MacroAssembler* _masm;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    40
  llvm::Value*    _base_pc;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    41
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    42
 private:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    43
  MacroAssembler* masm() const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    44
    return _masm;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    45
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    46
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    47
 public:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    48
  llvm::Value* base_pc() const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    49
    return _base_pc;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    50
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    51
  void set_base_pc(llvm::Value* base_pc) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    52
    assert(_base_pc == NULL, "only do this once");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    53
    _base_pc = base_pc;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    54
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    55
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    56
  // Allocate some space in the buffer and return its address.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    57
  // This buffer will have been relocated by the time the method
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    58
  // is installed, so you can't inline the result in code.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    59
 public:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    60
  void* malloc(size_t size) const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    61
    masm()->align(BytesPerWord);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    62
    void *result = masm()->pc();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    63
    masm()->advance(size);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    64
    return result;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    65
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    66
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    67
  // Create a unique offset in the buffer.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    68
 public:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    69
  int create_unique_offset() const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    70
    int offset = masm()->offset();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    71
    masm()->advance(1);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    72
    return offset;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    73
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    74
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    75
  // Inline an oop into the buffer and return its offset.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    76
 public:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    77
  int inline_oop(jobject object) const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    78
    masm()->align(BytesPerWord);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    79
    int offset = masm()->offset();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    80
    masm()->store_oop(object);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    81
    return offset;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    82
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    83
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    84
  // Inline a block of non-oop data into the buffer and return its offset.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    85
 public:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    86
  int inline_data(void *src, size_t size) const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    87
    masm()->align(BytesPerWord);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    88
    int offset = masm()->offset();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    89
    void *dst = masm()->pc();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    90
    masm()->advance(size);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    91
    memcpy(dst, src, size);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    92
    return offset;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    93
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    94
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    95
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    96
#endif // SHARE_VM_SHARK_SHARKCODEBUFFER_HPP