示例#1
0
/*
 * Dispose Environment
 *
 * Shutdown a JVMTI connection created with JNI GetEnv (see JVMTI
 * Environments). Dispose of any resources held by the environment.
 * Suspended threads are not resumed, this must be done explicitly
 * by the agent. Allocated memory is not released, this must be
 * done explicitly by the agent. This environment may not be used
 * after this call. This call returns to the caller.
 *
 * REQUIRED Functionality.
 */
jvmtiError JNICALL
jvmtiDisposeEnvironment(jvmtiEnv* env)
{
    TRACE2("jvmti.general", "DisposeEnvironment called, env = " << env);
    SuspendEnabledChecker sec;
    /*
     * Check given env & current phase.
     */
    jvmtiPhase* phases = NULL;

    CHECK_EVERYTHING();

    TIEnv *p_env = (TIEnv *)env;
    DebugUtilsTI *ti = p_env->vm->vm_env->TI;
    LMAutoUnlock lock(&ti->TIenvs_lock);

    // Disable all global events for this environment
    int iii;
    for (iii = JVMTI_MIN_EVENT_TYPE_VAL; iii <= JVMTI_MAX_EVENT_TYPE_VAL; iii++)
        remove_event_from_global(env, (jvmtiEvent)iii);

    // Disable all thread local events for this environment, do it only in live phase
    // otherwise environment couldn't register for any thread local events
    // because it couldn't get any live thread references
    jvmtiPhase ph;
    jvmtiGetPhase(env, &ph);
    if (JVMTI_PHASE_LIVE == ph)
    {
        // FIXME: this loop is very ugly, could we improve it?
        jint threads_number;
        jthread *threads;
        jvmtiGetAllThreads(env, &threads_number, &threads);
        for (int jjj = 0; jjj < threads_number; jjj++)
            for (iii = JVMTI_MIN_EVENT_TYPE_VAL; iii <= JVMTI_MAX_EVENT_TYPE_VAL; iii++)
                remove_event_from_thread(env, (jvmtiEvent)iii, threads[jjj]);
        _deallocate((unsigned char *)threads);
    }

    // Remove all breakpoints set by this environment and release interface
    ti->vm_brpt->release_intf(p_env->brpt_intf);

    // Remove all capabilities for this environment
    jvmtiRelinquishCapabilities(env, &p_env->posessed_capabilities);

    // Remove environment from the global list
    p_env->vm->vm_env->TI->removeEnvironment(p_env);

    _deallocate((unsigned char *)env);

    return JVMTI_ERROR_NONE;
}
示例#2
0
    /**
     * @brief Allocates the memory needed for this class
     * @return 1 on success, -1 on failure
     */
    virtual int32_t allocate()
    {
      if ((NULL != m_Array) && (true == m_OwnsData))
      {
        _deallocate();
      }
      m_Array = NULL;
      m_OwnsData = true;
      m_IsAllocated = false;
      if (m_Size == 0)
      {
        clear();
        return 1;
      }


      size_t newSize = m_Size;
#if defined ( AIM_USE_SSE ) && defined ( __SSE2__ )
      m_Array = static_cast<T*>( _mm_malloc (newSize * sizeof(T), 16) );
#else
      m_Array = (T*)malloc(newSize * sizeof(T));
#endif
      if (!m_Array)
      {
        qDebug() << "Unable to allocate " << newSize << " elements of size " << sizeof(T) << " bytes. " ;
        return -1;
      }
      m_Size = newSize;
      m_IsAllocated = true;

      return 1;
    }
示例#3
0
    /**
     * @brief Allocates the memory needed for this class
     * @return 1 on success, -1 on failure
     */
    virtual int32_t Allocate()
    {
      if ((NULL != this->Array) && (true == this->_ownsData))
      {
        _deallocate();
      }
      this->Array = NULL;
      this->_ownsData = true;
      m_IsAllocated = false;
      if (this->Size == 0)
      {
        initialize();
        return 1;
      }


      size_t newSize = this->Size;
#if defined ( AIM_USE_SSE ) && defined ( __SSE2__ )
      Array = static_cast<T*>( _mm_malloc (newSize * sizeof(T), 16) );
#else
      this->Array = (T*)malloc(newSize * sizeof(T));
#endif
      if (!this->Array)
      {
        std::cout << "Unable to allocate " << newSize << " elements of size " << sizeof(T) << " bytes. " << std::endl;
        return -1;
      }
      this->Size = newSize;
      m_IsAllocated = true;

      return 1;
    }
示例#4
0
 /**
  * @brief Destructor
  */
 virtual ~DataArray()
 {
   //qDebug() << "~DataArrayTemplate '" << m_Name << "'" ;
   if ((NULL != m_Array) && (true == m_OwnsData))
   {
     _deallocate();
   }
 }
示例#5
0
 /**
  * @brief Destructor
  */
 virtual ~DataArray()
 {
   //std::cout << "~DataArrayTemplate '" << m_Name << "'" << std::endl;
   if ((NULL != this->Array) && (true == this->_ownsData))
   {
     _deallocate();
   }
 }
示例#6
0
/*
 * Get Method Name (and Signature)
 *
 * For the method indicated by method, return the method name via
 * name_ptr and method signature via signature_ptr.
 *
 * REQUIRED Functionality.
 */
jvmtiError JNICALL
jvmtiGetMethodName(jvmtiEnv* env,
                   jmethodID method,
                   char** name_ptr,
                   char** signature_ptr,
                   char** generic_ptr)
{
    TRACE("GetMethodName called");
    SuspendEnabledChecker sec;
    /*
     * Check given env & current phase.
     */
    jvmtiPhase phases[] = {JVMTI_PHASE_START, JVMTI_PHASE_LIVE};

    CHECK_EVERYTHING();

    if( !method ) return JVMTI_ERROR_NULL_POINTER;
    // Either name_ptr, signature_ptr, or generic_ptr can be NULL
    // In this case they are not returned

    char* mtd_name;
    char* mtd_sig;
    Method* mtd = reinterpret_cast<Method*>(method);
    jvmtiError err;
    if( name_ptr )
    {
        const String* name = mtd->get_name();
        err = _allocate(name->len + 1, (unsigned char**)(&mtd_name));
        if(err != JVMTI_ERROR_NONE)
            return err;
        // copy method name
        strcpy(mtd_name, name->bytes);
        *name_ptr = mtd_name;
    }

    if( signature_ptr )
    {
        const String* sig = mtd->get_descriptor();
        err = _allocate(sig->len + 1, (unsigned char**)(&mtd_sig));
        if(err != JVMTI_ERROR_NONE)
        {
            if(name_ptr && mtd_name)
                _deallocate((unsigned char*)mtd_name);
            return err;
        }
        // copy method signature
        strcpy(mtd_sig, sig->bytes);
        *signature_ptr = mtd_sig;
    }

    // ppervov: no generics support in VM as of yet
    if( generic_ptr )
        *generic_ptr = NULL;

    return JVMTI_ERROR_NONE;
}
示例#7
0
    /**
     * @brief Initializes this class to zero bytes freeing any data that it currently owns
     */
    virtual void initialize()
    {
      if (NULL != this->Array && true == this->_ownsData)
      {
        _deallocate();
      }
      this->Array = NULL;
      this->Size = 0;
      this->_ownsData = true;
      this->MaxId = 0;
      m_IsAllocated = false;

      //   this->_dims[0] = _nElements;
    }
示例#8
0
 /**
  * @brief Removes all elements from the array (which are destroyed), leaving the container with a size of 0.
  */
 virtual void clear()
 {
   if (NULL != m_Array && true == m_OwnsData)
   {
     _deallocate();
   }
   m_Array = NULL;
   m_Size = 0;
   m_OwnsData = true;
   m_MaxId = 0;
   m_IsAllocated = false;
   m_NumTuples = 0;
   // We need to actually keep the numComps and the dimensions in case the user resizes the array
   //      m_CompDims.clear();
   //      m_NumComponents = 0;
 }
示例#9
0
McoStatus Matrix::set(int32 rows, int32 cols)
{
	_deallocate();
	_err = MCO_SUCCESS;
	
	if( rows <= 0 || cols <= 0){
		_err = MCO_FAILURE;
		return _err;
	}

	_row = rows;
	_col = cols;
	_allocate();
	
	return _err;
}
示例#10
0
//_row and _col must be set before calling this method
void Matrix::_allocate(void)
{
	_m =  (double**)McoMalloc(sizeof(double*)*_row);

	if(!_m)
		_err = MCO_MEM_ALLOC_ERROR;
	else{
		for(int32 i = 0; i < _row; i++){
			_m[i] = (double*)McoMalloc(sizeof(double)*_col);
			if(!_m[i]){	//not enough memory
				for(int32 j = i-1; j >= 0; j--)
					McoFree((void *) _m[j]);

				McoFree((void *) _m);
				_m = 0;
				_err = MCO_MEM_ALLOC_ERROR;
				break;
			}
		}
	}

	//modified on 8/12 to take out smatrix class
	//for square matrix, also need to allocate for the
	//additional memory 	
	_indx = 0;
	if( _row == _col){
		if(_err == MCO_SUCCESS){
			_indx = (double*)McoMalloc(sizeof(double)*_row);
			if(!_indx){
				_deallocate();
				_err = MCO_MEM_ALLOC_ERROR;
				return;
			}
		}
	}
	//end of modification

}
示例#11
0
NeuralNetwork::~NeuralNetwork() {
  _deallocate();
}
示例#12
0
MeshRenderer::~MeshRenderer(){
	_deallocate();
	glDeleteBuffers(1,&vbo);
	glDeleteBuffers(1,&ibo);
}
示例#13
0
    /**
     * @brief Removes Tuples from the m_Array. If the size of the vector is Zero nothing is done. If the size of the
     * vector is greater than or Equal to the number of Tuples then the m_Array is Resized to Zero. If there are
     * indices that are larger than the size of the original (before erasing operations) then an error code (-100) is
     * returned from the program.
     * @param idxs The indices to remove
     * @return error code.
     */
    virtual int eraseTuples(QVector<size_t>& idxs)
    {

      int err = 0;

      // If nothing is to be erased just return
      if(idxs.size() == 0)
      {
        return 0;
      }
      size_t idxs_size = static_cast<size_t>(idxs.size());
      if (idxs_size >= getNumberOfTuples() )
      {
        resize(0);
        return 0;
      }

      // Sanity Check the Indices in the vector to make sure we are not trying to remove any indices that are
      // off the end of the array and return an error code.
      for(QVector<size_t>::size_type i = 0; i < idxs.size(); ++i)
      {
        if (idxs[i] * m_NumComponents > m_MaxId) { return -100; }
      }

      // Calculate the new size of the array to copy into
      size_t newSize = (getNumberOfTuples() - idxs.size()) * m_NumComponents ;

      // Create a new m_Array to copy into
      T* newArray = (T*)malloc(newSize * sizeof(T));
      // Splat AB across the array so we know if we are copying the values or not
      ::memset(newArray, 0xAB, newSize * sizeof(T));

      // Keep the current Destination Pointer
      T* currentDest = newArray;
      size_t j = 0;
      int k = 0;
      // Find the first chunk to copy by walking the idxs array until we get an
      // index that is NOT a continuous increment from the start
      for (k = 0; k < idxs.size(); ++k)
      {
        if(j == idxs[k])
        {
          ++j;
        }
        else
        {
          break;
        }
      }

      if(k == idxs.size()) // Only front elements are being dropped
      {
        T* currentSrc = m_Array + (j * m_NumComponents);
        ::memcpy(currentDest, currentSrc, (getNumberOfTuples() - idxs.size()) * m_NumComponents * sizeof(T));
        _deallocate(); // We are done copying - delete the current m_Array
        m_Size = newSize;
        m_Array = newArray;
        m_OwnsData = true;
        m_MaxId = newSize - 1;
        m_IsAllocated = true;
        return 0;
      }

      QVector<size_t> srcIdx(idxs.size() + 1);
      QVector<size_t> destIdx(idxs.size() + 1);
      QVector<size_t> copyElements(idxs.size() + 1);
      srcIdx[0] = 0;
      destIdx[0] = 0;
      copyElements[0] = (idxs[0] - 0) * m_NumComponents;

      for (int i = 1; i < srcIdx.size(); ++i)
      {
        srcIdx[i] = (idxs[i - 1] + 1) * m_NumComponents;

        if(i < srcIdx.size() - 1)
        {
          copyElements[i] = (idxs[i] - idxs[i - 1] - 1) * m_NumComponents;
        }
        else
        {
          copyElements[i] = (getNumberOfTuples() - idxs[i - 1] - 1) * m_NumComponents;
        }
        destIdx[i] = copyElements[i - 1] + destIdx[i - 1];
      }

      // Copy the data
      for (int i = 0; i < srcIdx.size(); ++i)
      {
        currentDest = newArray + destIdx[i];
        T* currentSrc = m_Array + srcIdx[i];
        size_t bytes = copyElements[i] * sizeof(T);
        ::memcpy(currentDest, currentSrc, bytes);
      }

      // We are done copying - delete the current m_Array
      _deallocate();

      // Allocation was successful.  Save it.
      m_Size = newSize;
      m_Array = newArray;
      // This object has now allocated its memory and owns it.
      m_OwnsData = true;
      m_IsAllocated = true;
      m_MaxId = newSize - 1;

      return err;
    }
示例#14
0
Matrix::~Matrix(void)
{
	_deallocate();
}