void ConcurrentG1Refine::update_thread_thresholds() {
  for (uint i = 0; i < _n_worker_threads; i++) {
    Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, i);
    _threads[i]->update_thresholds(activation_level(thresholds),
                                   deactivation_level(thresholds));
  }
}
/*
 * this func can be called from other modules in kernel.
 */
int set_hmp_policy(const char *pname, int prio, int state,
		int up_thresholds, int down_thresholds)
{
	unsigned int len_name = 0;
	int ret = 0;
	unsigned int i = 0;

	if (!hmpset_enable && prio)
		 return 0;

	/*check if args has legal value.*/
	len_name = strlen(pname);
	if ((len_name < 2) || (len_name > 15)) {
		pr_err("hmpth--err_input--name_length");
		goto err_input;
	}
	while (i < len_name) {
		ret += islowchac(pname[i]);
		i++;
	}
	if (ret != len_name) {
		hmpth_debug("DEBUG: ret %d, len_name %d.\n", ret, len_name);
		pr_err("hmpth--err_inputt--name must be [a-z] only");
		goto err_input;
	}
	if ((prio < PRIOR_0) || (prio > PRIOR_5)) {
		pr_err("hmpth--err_inputt--prio");
		goto err_input;
	}
	if ((state < STATE_OFF) || (state > STATE_ON)) {
		pr_err("hmpth--err_inputt--state");
		goto err_input;
	}
	if ((up_thresholds < MIN_THRESHOLDS)
		|| (up_thresholds > MAX_THRESHOLDS)) {
		pr_err("hmpth--err_input--up");
		goto err_input;
	}
	if ((down_thresholds < MIN_THRESHOLDS)
		|| (down_thresholds > MAX_THRESHOLDS)) {
		pr_err("hmpth--err_input--down");
		goto err_input;
	}
	if ((down_thresholds + UP_MUST_BIG_THAN_DOWN) > up_thresholds) {
		pr_err("hmpth err input:up - down < 100.\n");
		goto err_input;
	}

	/*
	 * only "default" can be PRIOR_0,
	 * and default can NOT be set to OFF
	 */
	if (PRIOR_0 == prio) {
		if ((len_name != strlen(DEFAULT_POLICY_NAME))
			|| (0 != strncmp(pname, DEFAULT_POLICY_NAME, len_name))
			|| (STATE_ON != state)) {
			pr_err("PRIOR_0 must be default,and must be ON.\n");
			goto err_input;
		}
	}

	/* ---------prevent concurrent-------mutex_lock------*/
	spin_lock_bh(&hmpset_lock);
	hmpth_debug("DEBUG lock: [%s], %d, %d, %d, %d.\n", pname, prio, state,
			up_thresholds, down_thresholds);

	/*fill the input policy into hmp_policy*/
	ret = fill_policy_in(pname, prio, state,
		up_thresholds, down_thresholds);
	if (ret < 0)
		return -1;
	debug_hmp_policy_struct("fill_policy_in", &hmp_policy[0]);
	/*rearrange policys by priority*/
	rearrange_policys();
	debug_hmp_policy_struct("calc_thresholds.", &pri_hmp_policy[0]);

	/*calc the proper thresholds*/
	calc_thresholds();
	spin_unlock_bh(&hmpset_lock);
	/*---------prevent concurrent-------mutex_unlock------*/

	return 0;

err_input:
	pr_err(": illegal values!\n");
	pr_err("%s, %d, %d, %d, %d.\n",
		pname, prio, state, up_thresholds, down_thresholds);
	return -1;

}
ConcurrentG1Refine* ConcurrentG1Refine::create(CardTableEntryClosure* refine_closure,
                                               jint* ecode) {
  size_t min_yellow_zone_size = calc_min_yellow_zone_size();
  size_t green_zone = calc_init_green_zone();
  size_t yellow_zone = calc_init_yellow_zone(green_zone, min_yellow_zone_size);
  size_t red_zone = calc_init_red_zone(green_zone, yellow_zone);

  LOG_ZONES("Initial Refinement Zones: "
            "green: " SIZE_FORMAT ", "
            "yellow: " SIZE_FORMAT ", "
            "red: " SIZE_FORMAT ", "
            "min yellow size: " SIZE_FORMAT,
            green_zone, yellow_zone, red_zone, min_yellow_zone_size);

  ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(green_zone,
                                                    yellow_zone,
                                                    red_zone,
                                                    min_yellow_zone_size);

  if (cg1r == NULL) {
    *ecode = JNI_ENOMEM;
    vm_shutdown_during_initialization("Could not create ConcurrentG1Refine");
    return NULL;
  }

  cg1r->_threads = NEW_C_HEAP_ARRAY_RETURN_NULL(ConcurrentG1RefineThread*, cg1r->_n_worker_threads, mtGC);
  if (cg1r->_threads == NULL) {
    *ecode = JNI_ENOMEM;
    vm_shutdown_during_initialization("Could not allocate an array for ConcurrentG1RefineThread");
    return NULL;
  }

  uint worker_id_offset = DirtyCardQueueSet::num_par_ids();

  ConcurrentG1RefineThread *next = NULL;
  for (uint i = cg1r->_n_worker_threads - 1; i != UINT_MAX; i--) {
    Thresholds thresholds = calc_thresholds(green_zone, yellow_zone, i);
    ConcurrentG1RefineThread* t =
      new ConcurrentG1RefineThread(cg1r,
                                   next,
                                   refine_closure,
                                   worker_id_offset,
                                   i,
                                   activation_level(thresholds),
                                   deactivation_level(thresholds));
    assert(t != NULL, "Conc refine should have been created");
    if (t->osthread() == NULL) {
      *ecode = JNI_ENOMEM;
      vm_shutdown_during_initialization("Could not create ConcurrentG1RefineThread");
      return NULL;
    }

    assert(t->cg1r() == cg1r, "Conc refine thread should refer to this");
    cg1r->_threads[i] = t;
    next = t;
  }

  cg1r->_sample_thread = new G1YoungRemSetSamplingThread();
  if (cg1r->_sample_thread->osthread() == NULL) {
    *ecode = JNI_ENOMEM;
    vm_shutdown_during_initialization("Could not create G1YoungRemSetSamplingThread");
    return NULL;
  }

  *ecode = JNI_OK;
  return cg1r;
}